使用ListAdapter显示数据库中的数据 [英] Using a ListAdapter to show database data
本文介绍了使用ListAdapter显示数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class List_View extends ListActivity {
private TextView toptext;
private TextView bottomtext;
DBAdapter db = new DBAdapter(this);
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.list);
getData();
toptext = (TextView) findViewById(R.id.toptext);
bottomtext = (TextView) findViewById(R.id.bottomtext);
}
private void getData() {
db.open();
Cursor c = db.getAllEntry();
c.moveToFirst();
ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.view_list, c, new String[] {"date", "title"}, new int[] {R.id.toptext, R.id.bottomtext});
bottomtext.setText(c.getString(1));
toptext.setText(c.getString(4));
setListAdapter(adapter);
db.close();
}
}
我想从数据库中存储的数据显示成一个ListView。
I would like to show stored data from database into a ListView.
标题和日期而已。
推荐答案
只是看了一眼在它;设置的TopText和bottomtext之前你要调用的getData谎言。
Just glancing over it; your call to getData lies before toptext and bottomtext is set.
这篇关于使用ListAdapter显示数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文