2009-11-08 7 views
3

필자는 APIDemos를 조사한 결과 텍스트가 보이는 갤러리의 예가 있지만 코드는 Cursor를 사용하지만 String 배열을 사용하려고합니다. 이 일을 어떻게하면 될까요?안드로이드 갤러리 텍스트 전용

 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 }); 

답변

4

, ArrayAdapter가 수행해야합니다

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

을하지만, 나중에 목록에 더 String 개체를 추가 할 수 있도록하려면, 당신은 사용해야합니다 a List.

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

감사합니다. –

4

당신은 ArrayAdapter으로 CursorAdapter를 교체해야합니다 :이 API 데모의 예제 코드입니다. 그냥 String 객체의 정적 목록을 표시하려면

+0

둘 다 맞습니다. –

관련 문제