这是我用于Listview的代码,我参考了一些网站 . 它显示了整个图像列表 . 我必须在数据库中放置哪个区域来设置toptext和bottom text的文本?
公共类List_View扩展ListActivity {
私有DBAdapter db;
私有TextView toptext;私有TextView底层文本;私人ListView lv;
public void onCreate(Bundle savedInstanceState){try {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
db = new DBAdapter(this);
toptext = (TextView) findViewById (R.id.toptext);
bottomtext = (TextView) findViewById (R.id.bottomtext);
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
HashMap<String, String> item;
for (int i = 0; i < 31; i++) {
item = new HashMap<String, String>();
item.put("Date:", "Saved Date" );
item.put("Title:", "Saved Title" );
list.add(item);
}
SimpleAdapter notes = new SimpleAdapter(this, list, R.layout.view_list,
new String[] { "date", "title" },
new int[] {R.id.toptext, R.id.bottomtext });
setListAdapter(notes);
} catch(Throwable e){
Log.e("DBAdapter",e.toString());
}}
这是数据库的一部分 .
public Cursor getAllEntry()
{
return db.query(DATABASE_TABLE_2, new String[] {
KEY_ROWID2,
KEY_TITLE,
KEY_ENTRY,
KEY_MOOD,
KEY_DATE,
KEY_TIME},
null,
null,
null,
null,
null,
null);
}
1 回答
你的代码中的一些修改......你得到了结果
首先在ListActivity类中声明Cursor,Adapter类
您必须在应用程序中创建NCursorAdapter类 .
这里的data.xml文件是你的自定义布局 . 哪个内容有两个textview ....“title”和“date”你的数据库表列名...