安卓画廊仅显示文本

5

我查看了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 });
2个回答

5

如果您只想显示一个静态的String对象列表,可以使用ArrayAdapter

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new String[] {People.NAME});

然而,如果你想随后添加更多的String对象到列表中,你应该使用一个List

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new ArrayList<String>());

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接