代码之家  ›  专栏  ›  技术社区  ›  Faisal Abid

仅限Android Gallery文本

  •  3
  • Faisal Abid  · 技术社区  · 15 年前

    我研究了Apidemos,他们有一个画廊的例子,在那里他们只显示文本,但是代码只使用光标,但是我想使用一个字符串数组。我该怎么做呢?这是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 回复  |  直到 15 年前
        1
  •  4
  •   kwogger    15 年前

    如果只想显示 String 对象,一个 ArrayAdapter 应该做:

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

    但是,如果您希望能够添加更多 对象到列表后,应使用 List .

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new ArrayList<String>());
    
        2
  •  4
  •   David Webb    15 年前

    你需要更换 CursorAdapter 用一个 ArrayAdapter .