Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gallery Text Only

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 });
like image 370
Faisal Abid Avatar asked Nov 08 '09 05:11

Faisal Abid


2 Answers

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>());
like image 122
kwogger Avatar answered Oct 20 '22 10:10

kwogger


You need to replace the CursorAdapter with an ArrayAdapter.

like image 44
Dave Webb Avatar answered Oct 20 '22 11:10

Dave Webb