這是關於約會。在android中查看數據庫
我有5個頁面依次鏈接。
在第4頁中,數據從用戶在第3頁中給出的數據進入數據庫。
用戶確認預約日期和時間,用戶應查看列表視圖形式的數據庫之前...
這是我所編碼。你能幫我解決嗎?
我的基本適配器類:
public class viewlistadapter extends BaseAdapter
{
SQLiteDatabase sdb;
private Context viewcontext;
ArrayList v1=new ArrayList();
ArrayList v2=new ArrayList();
ArrayList v3=new ArrayList();
ArrayList v4=new ArrayList();
ArrayList v5=new ArrayList();
int length;
public viewlistadapter(viewlist vl, ArrayList value12, ArrayList value22, ArrayList value32, ArrayList value42, ArrayList value52)
{
viewcontext=vl;
v1=value12;
v2=value22;
v3=value32;
v4=value42;
v5=value52;
length=v1.size();
}
public viewlistadapter(viewlist vl, String value12, String value22,
String value32, String value42, String value52)
{
// TODO Auto-generated constructor stub
}
public int getCount()
{
// TODO Auto-generated method stub
return length;
}
public Object getItem(int arg0)
{
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position)
{
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
LinearLayout l=new LinearLayout(viewcontext);
TextView tv1=new TextView(viewcontext);
TextView tv2=new TextView(viewcontext);
TextView tv3=new TextView(viewcontext);
TextView tv4=new TextView(viewcontext);
TextView tv5=new TextView(viewcontext);
tv1.setText((String) v1.get(position));
tv2.setText((String) v2.get(position));
tv3.setText((String) v3.get(position));
tv4.setText((String) v4.get(position));
tv5.setText((String) v5.get(position));
l.addView(tv1);
l.addView(tv2);
l.addView(tv3);
l.addView(tv4);
l.addView(tv5);
return l;
}
}
和活動類是
public class viewlist extends Activity
{
TextView viewtv1;
Button viewbutt;
ListView lv;
TextView statustv;
viewlistadapter vla;
SQLiteDatabase db=null;
SQLiteDatabase sdb;
final String path="/data/data/a.b.seventeenth/databases/";
final String dbname="checking2.db";
ArrayList value12=new ArrayList();
ArrayList value22=new ArrayList();
ArrayList value32=new ArrayList();
ArrayList value42=new ArrayList();
ArrayList value52=new ArrayList();
public void createdb()
{
try
{
sdb=openOrCreateDatabase("checking2.db",Context.MODE_PRIVATE, null);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.toString(), 5000).show();
}
}
public void viewdb()
{
try
{
sdb=openOrCreateDatabase("checking2.db",Context.MODE_PRIVATE, null);
lv=(ListView) findViewById(R.id.lv);
String res="";
Cursor c=sdb.query("login",null, null, null, null, null, null);
c.moveToFirst();
while(!c.isAfterLast())
{
value12.add(c.getString(c.getColumnIndex("name")));
value22.add(c.getString(c.getColumnIndex("date")));
value32.add(c.getString(c.getColumnIndex("month")));
value42.add(c.getString(c.getColumnIndex("hours")));
value52.add(c.getString(c.getColumnIndex("minutes")));
c.moveToNext();
/*status=sdb.view("login", null, value12);
return status;*/
//long s=sdb.insertOrThrow("login", null, value12); //long s= sdb.view("login", null, value12);
}
lv.setAdapter(new viewlistadapter(this,value12,value22,value32,value42,value52));
}
catch (Exception e)
{
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.toString(), 500000).show();
}
}
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listviewform);
viewbutt=(Button) findViewById(R.id.viewbutt);
lv=(ListView) findViewById(R.id.lv);
statustv=(TextView) findViewById(R.id.statustv);
try
{
sdb=SQLiteDatabase.openDatabase(path+dbname,null ,SQLiteDatabase.OPEN_READONLY);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
try {
if(db==null)
{
statustv.setText("no one has booked the appointment for today!!");
}
else
{
viewdb();
}
} catch (Exception e1) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e1.toString(), 500000).show();
}
*/
//statustv.setText(text, type)
try {
viewbutt.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
try
{
Bundle b=viewlist.this.getIntent().getExtras();
String name=b.getString("name");
int date=b.getInt("date");
int month=b.getInt("month");
int hour=b.getInt("hour");
int minutes=b.getInt("minutes");
Intent i=new Intent(getApplicationContext(),register.class);
//Toast.makeText(getApplicationContext(), String.valueOf(date)+String.valueOf(hour)+String.valueOf(minutes), 5000).show();
i.putExtra("name",name);
/*a.putExtra("phone_no",phone_no);
a.putExtra("email", email);*/
i.putExtra("date", date);
i.putExtra("month", month);
i.putExtra("hour", hour);
i.putExtra("minutes", minutes);
i.putExtra("name", name);
startActivity(i);
} catch (Exception e)
{
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.toString(), 5000).show();
}
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.toString(), 500000).show();
}
}
}
這個問題真的很廣泛。在發佈問題之前,您應該儘可能縮小範圍。 – fiddler
當然我會拿c是它的naext時間,小提琴手...你能幫我解決它嗎...請... – elegance