这是我的数据库代码:package com.example.SQLite;import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class Casequery extends SQLiteOpenHelper{ //数据库名称
private final static String NAME="modelpolice";
//数据库版本号
private final static int VERSION=1;
public Casequery(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
public Casequery(Context context,String name,int version) {
this(context,name,null,version);
}
public Casequery(Context context,String name) {
this(context,name,VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
System.out.println("create database");
String sql="create table case(Id integer default'1'not null primary key autoincrement" +
",Time time not null,Reason varchar(50) not null,People varchar(20) not null" +
",Native varchar(50) not null,BegincaseTime time not null,EndcaseTime time not null," +
"FilingTime time not null" +
",Workpeople varchar(20) not null,Site varchar(50) not null)";
db.execSQL(sql);
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
System.out.println("update database");
}}
这是选项卡:package com.example.tabwidget1;import android.app.TabActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;import com.example.SQLite.Casequery;public class CaseInquires extends TabActivity{
TabHost mTabHost;
public Button btn;
public Button btncx;
private TextView time;
private TextView people;
private TextView workpeople;
private TextView site;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.tabmain);
btn=(Button)findViewById(R.id.btn);
btncx=(Button)findViewById(R.id.btcx);
time = (TextView)findViewById(R.id.time);
people = (TextView)findViewById(R.id.people);
workpeople = (TextView)findViewById(R.id.workpeople);
site = (TextView)findViewById(R.id.site);
btn.setOnClickListener(new QueryListener());
mTabHost=getTabHost();
LayoutInflater.from(this).inflate(R.layout.tabmain, mTabHost.getTabContentView(), true);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("简单查询").setContent(R.id.tab1));
mTabHost.addTab(mTabHost.newTabSpec("Tab_test2").setIndicator("详细查询").setContent(R.id.tab2));
mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
mTabHost.setCurrentTab(0);
mTabHost.setOnTabChangedListener(new OnTabChangeListener(){ public void onTabChanged(String tabId) {
// TODO Auto-generated method stub }
});
}
class QueryListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
}
这是选项卡的布局文件:<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/TVId"
android:text="请输入案件ID:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginLeft="100dp"
android:textSize="20sp"
/>
<EditText
android:id="@+id/ETId"
android:layout_centerInParent="true"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="请输入案件ID"
/>
<Button
android:id="@+id/btn"
android:layout_below="@id/ETId"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="查 询"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="收案时间:"/>"
<EditText
android:id="@+id/ETSA"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/time"
android:layout_marginTop="35dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="@+id/people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/time"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="当 事 人:"/>
<EditText
android:id="@+id/ETXY"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/time"
android:layout_marginTop="24dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@id/ETSA"
/>
<TextView
android:id="@+id/workpeople"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/people"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="执勤交警:"/>
<EditText
android:id="@+id/ETJJ"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/workpeople"
android:layout_marginTop="24dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@id/ETXY"
/>
<TextView
android:id="@+id/site"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/workpeople"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="地 点:"/>
<EditText
android:id="@+id/ETDD"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/site"
android:layout_marginTop="24dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@id/ETJJ"
/>
<Button
android:id="@+id/btcx"
android:layout_margin="60dp"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ETDD"
android:text="查 询"
/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>我想在两个tab中都做查询按钮,在第一个tab中点查询后跳到一个显示详细信息的界面,第二个tab中不一定都写,然后点查询,跳到listview显示界面,然后点listview任何一个数据就会跳到详细信息的界面。目前的状况是程序不能运行,把btn的监听器去掉就能运行,但不知道后面该怎么写。
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class Casequery extends SQLiteOpenHelper{ //数据库名称
private final static String NAME="modelpolice";
//数据库版本号
private final static int VERSION=1;
public Casequery(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
public Casequery(Context context,String name,int version) {
this(context,name,null,version);
}
public Casequery(Context context,String name) {
this(context,name,VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
System.out.println("create database");
String sql="create table case(Id integer default'1'not null primary key autoincrement" +
",Time time not null,Reason varchar(50) not null,People varchar(20) not null" +
",Native varchar(50) not null,BegincaseTime time not null,EndcaseTime time not null," +
"FilingTime time not null" +
",Workpeople varchar(20) not null,Site varchar(50) not null)";
db.execSQL(sql);
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
System.out.println("update database");
}}
这是选项卡:package com.example.tabwidget1;import android.app.TabActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;import com.example.SQLite.Casequery;public class CaseInquires extends TabActivity{
TabHost mTabHost;
public Button btn;
public Button btncx;
private TextView time;
private TextView people;
private TextView workpeople;
private TextView site;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.tabmain);
btn=(Button)findViewById(R.id.btn);
btncx=(Button)findViewById(R.id.btcx);
time = (TextView)findViewById(R.id.time);
people = (TextView)findViewById(R.id.people);
workpeople = (TextView)findViewById(R.id.workpeople);
site = (TextView)findViewById(R.id.site);
btn.setOnClickListener(new QueryListener());
mTabHost=getTabHost();
LayoutInflater.from(this).inflate(R.layout.tabmain, mTabHost.getTabContentView(), true);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("简单查询").setContent(R.id.tab1));
mTabHost.addTab(mTabHost.newTabSpec("Tab_test2").setIndicator("详细查询").setContent(R.id.tab2));
mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
mTabHost.setCurrentTab(0);
mTabHost.setOnTabChangedListener(new OnTabChangeListener(){ public void onTabChanged(String tabId) {
// TODO Auto-generated method stub }
});
}
class QueryListener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
}
这是选项卡的布局文件:<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/TVId"
android:text="请输入案件ID:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginLeft="100dp"
android:textSize="20sp"
/>
<EditText
android:id="@+id/ETId"
android:layout_centerInParent="true"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="请输入案件ID"
/>
<Button
android:id="@+id/btn"
android:layout_below="@id/ETId"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="查 询"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="收案时间:"/>"
<EditText
android:id="@+id/ETSA"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/time"
android:layout_marginTop="35dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="@+id/people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/time"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="当 事 人:"/>
<EditText
android:id="@+id/ETXY"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/time"
android:layout_marginTop="24dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@id/ETSA"
/>
<TextView
android:id="@+id/workpeople"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/people"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="执勤交警:"/>
<EditText
android:id="@+id/ETJJ"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/workpeople"
android:layout_marginTop="24dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@id/ETXY"
/>
<TextView
android:id="@+id/site"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/workpeople"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="地 点:"/>
<EditText
android:id="@+id/ETDD"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_toRightOf="@id/site"
android:layout_marginTop="24dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@id/ETJJ"
/>
<Button
android:id="@+id/btcx"
android:layout_margin="60dp"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ETDD"
android:text="查 询"
/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>我想在两个tab中都做查询按钮,在第一个tab中点查询后跳到一个显示详细信息的界面,第二个tab中不一定都写,然后点查询,跳到listview显示界面,然后点listview任何一个数据就会跳到详细信息的界面。目前的状况是程序不能运行,把btn的监听器去掉就能运行,但不知道后面该怎么写。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货