如何在android中的SimpleCursorAdapter列表上使用LayoutInflater?
给出了 SimpleCursorAdapter 实现代码示例:
String[] projection = new String[] {Browser.BookmarkColumns._ID,
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL};
String[] displayFields = new String[] {Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL};
int[] displayViews = new int[] { android.R.id.text1,
android.R.id.text2 };
Cursor cur = managedQuery(android.provider.Browser.BOOKMARKS_URI,
projection, null, null, null);
setListAdapter(new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, cur,
displayFields, displayViews));
How can I use my own xml layout to show those list using LayoutInflater?
或者也许我可以说“制作我自己的 simple_list_item_2.xml”....
谢谢
given an example SimpleCursorAdapter implementation code:
String[] projection = new String[] {Browser.BookmarkColumns._ID,
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL};
String[] displayFields = new String[] {Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL};
int[] displayViews = new int[] { android.R.id.text1,
android.R.id.text2 };
Cursor cur = managedQuery(android.provider.Browser.BOOKMARKS_URI,
projection, null, null, null);
setListAdapter(new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, cur,
displayFields, displayViews));
How can I use my own xml layout to show those list using LayoutInflater?
or maybe I could say "to make my own simple_list_item_2.xml"....
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SimpleCursorAdapter
为您处理布局膨胀。您只需在res/layout/my_list_item.xml
中创建布局,然后将android.R.layout.simple_list_item_2
更改为R.layout.my_list_item
代码>.您还可以将
android.R.id.text1
更改为要在布局中绑定TITLE
列的TextView
的 id,例如R.id.title
。URL
列也是如此。您可以从 simple_list_item_2.xml 并尝试根据您的需要进行编辑,将其保存到
res/layout/my_list_item.xml
或无论您想要什么布局名称。SimpleCursorAdapter
handles the layout inflation for you. You just need to create your layout inres/layout/my_list_item.xml
and then changeandroid.R.layout.simple_list_item_2
toR.layout.my_list_item
.You would also change
android.R.id.text1
to the id of theTextView
you want to bind theTITLE
column to in your layout, for exampleR.id.title
. Likewise for theURL
column.You can start with a copy of simple_list_item_2.xml and experiment with editing it for your needs, saving it to
res/layout/my_list_item.xml
or whatever layout name you want.