您的位置:首页 > 移动开发 > Android开发

【android】BasaAdapter不能用了,SimpleAdapter/SimpleCursorAdapter怎么用呢

2018-01-12 09:00 603 查看
比如,我需要制作一个列表页面,我可以使用ListView,这样每个列表项只能显示一个文本。如果我需要在每个列表项显示多个文本,这个时候就需要适配器了。BaseAdapter现在已经不能使用了比较繁琐,需要实现一个复杂的getView函数。取而代之的是SimpleAdapter,SimpleCursorAdapter是用来直接和SQLite对接的,非常方便。
Cursor cursor = mtcDbAdapter.getAllTracks();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.listview_item,cursor,new String[] {"name","desc","created_at"},
new int[] {R.id.name,R.id.desc,R.id.time},0);
ListView listView = findViewById(R.id.list);
listView.setAdapter(adapter);
注意:产生cursor的query函数所查询的主键名必须是“_id”,因为这源于SQLite的规范,主键以“_id”为标准。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: