Pregunta
He mirado en las API Demos y tienen un ejemplo de la galería donde se muestran solo texto, el código sólo utiliza un cursor, sin embargo quiero usar una matriz de cadenas. ¿Cómo puedo lograr usarlo? Este es el código para el ejemplo de Demos 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 });
Solución
Si lo que desea es visualizar una lista estática de los objetos String
, un ArrayAdapter
debe hacer:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new String[] {People.NAME});
Sin embargo, si usted quiere ser capaz de añadir más objetos String
a la lista más adelante, se debe utilizar un List
.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new ArrayList<String>());
Otros consejos
Es necesario sustituir el CursorAdapter
con un ArrayAdapter
.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow