我開發了一些短信應用程序,我無法弄清楚如何解決這個問題......在一個佈局中,我顯示兩個文本查看來顯示數字和日期的短信...工作正常...從另一個類的數據填充類的textview
但現在我正在實施onListItemClick,我希望當單擊列表項時,從數據庫的整個消息應加載到新的視圖....如何我完成了...
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
dba.open();
Cursor c=dba.executeQuery("select rowid _id,* from messages where rowid="+position+";");
Log.v(tag, "value count"+ c.getCount());
if(c.getCount()>0)
{
Log.v(tag, "value count"+c.getCount());
c.moveToPosition(position);
Intent intent = new Intent();
String mesage = c.getString(c.getColumnIndex("msg"));
Log.v("Value passed to class", mesage);
intent.putExtra(name, mesage);
intent.setClass(this, NewInterface.class);
startActivity(intent);
}
}
這裏是我傳遞數據的其他類的代碼。
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.messages);
tv4 = (TextView) findViewById(R.id.tvMessages);
Bundle bundle=getIntent().getExtras();
if(bundle!=null)
{
Log.v("Value got from class", bundle.getString("name"));
tv4.setText(bundle.getString("name"));
}
列表視圖通過從包含電話號碼數據庫,這種方法填充....
私人無效openAndQueryDatabase(){
newDB=new DBAdapter(this);
try {
newDB.open();
Cursor c = newDB.executeQuery("select distinct nm,rowid _id from messages");
if (c != null) {
if (c.moveToFirst())
Log.v(tag, "Stage 1");{
do {
String firstName = c.getString(c.getColumnIndex("nm"));
Log.v(tag, firstName);
// String date = c.getString(c.getColumnIndex("dt"));
results.add(firstName);
}while (c.moveToNext());
Log.v(tag, "Stage 1");
}
}
您面臨的問題是什麼 – Ishu 2012-04-01 06:29:02
我希望當用戶點擊某個listitem時,它會獲取顯示在特定listviewitem上的電話號碼,然後對該號碼執行數據庫查詢並獲取消息並傳遞該數據到另一個類顯示它在不同的佈局... – kashifmehmood 2012-04-01 11:00:11
你可以添加你的getview()或什麼listview項目包含我的意思是數據 – Ishu 2012-04-01 11:04:35