i have a method that return a ArrayList from a sqlite query, only a 1 row, this array must have 3 strings; name,description and photo(This is a patch string). But i don't know how i can separate the data.
public ArrayList<Object> getLugarPorNombre(String nombre)
{
ArrayList<Object> rowArray = new ArrayList<Object>();
Cursor cursor;
try
{
cursor = db.query
(
TABLE_NAME,
new String[] { TABLE_ROW_ID, CNOMBRE, CDESC, CFOTO开发者_开发百科 },
CNOMBRE + "=" + nombre,
null, null, null, null, null
);
//movemos el puntero a la primera posicion
cursor.moveToFirst();
// Si hay datos los añado al array que sera devuelto
if (!cursor.isAfterLast())
{
do
{
rowArray.add(cursor.getLong(0));
rowArray.add(cursor.getString(1));
rowArray.add(cursor.getString(2));
rowArray.add(cursor.getString(3));
}
while (cursor.moveToNext());
}
cursor.close();
}
catch (SQLException e)
{
Log.e("Error obteniendo datos de lugar", e.toString());
e.printStackTrace();
}
return rowArray;
}
and
ayudabbdd = new DataBaseHelper(this);
ArrayList<Object> datosLugar = ayudabbdd.getLugarPorNombre(nombreClick);
Can i get the name from array list or description in a separate string?
Do you mean something like that:
String name = (String) datosLugar.get(1);
String description = (String) datosLugar.get(2);
You have to be sure that element 1 & 2 are always Strings othweise you will get a ClassCastException. If you would like to make that cleaner you could probably create an own class for your return type.
Sure you can.But your ArrayList has 4 items not 3 as you mentioned in your question above.just you have to play with ArrayList like this
String name=datosLugar.get(1).toString();
String description=datosLugar.get(2).toString();
精彩评论