views:

914

answers:

2

Ive looked into the APIDemos and they have an example of the gallery where they show just text, the code however just uses a Cursor , however I want to use a String array. how would i go about doing this? 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 });
+2  A: 

You need to replace the CursorAdapter with an ArrayAdapter.

Dave Webb
you both are correct :)
Faisal Abid
+2  A: 

If you just want to display a static list of String objects, an ArrayAdapter should do:

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

However, if you want to be able to add more String objects to the list later, you should use a List.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new ArrayList<String>());
spaceboy2000
Thanks man, worked like a charm!
Faisal Abid