Android 图库仅文本
我查看了 API 演示,他们有一个画廊示例,其中仅显示文本,代码仅使用 Cursor ,但是我想使用 String 数组。我怎样才能使用它来实现?这是 API 演示中示例的代码:
Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(c);
SpinnerAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_gallery_item,
// Give the cursor to the list adatper
c,
// Map the NAME column in the people database to...
new String[] {People.NAME},
// The "text1" view defined in the XML template
new int[] { android.R.id.text1 });
I've looked into the API Demos and they have an example of the gallery where they show just text, the code just uses a Cursor , however I want to use a String array. How can I achieve using it? This is the code for the example in API Demos:
Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(c);
SpinnerAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_gallery_item,
// Give the cursor to the list adatper
c,
// Map the NAME column in the people database to...
new String[] {People.NAME},
// The "text1" view defined in the XML template
new int[] { android.R.id.text1 });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想显示
String
对象的静态列表,则ArrayAdapter
应该这样做:但是,如果您希望稍后能够向列表添加更多
String
对象,则应该使用List
。If you just want to display a static list of
String
objects, anArrayAdapter
should do:However, if you want to be able to add more
String
objects to the list later, you should use aList
.您需要将
CursorAdapter
替换为ArrayAdapter
。You need to replace the
CursorAdapter
with anArrayAdapter
.