samedi 31 janvier 2015

Android SQLite: Spinner + select sql methods

I have a Spinner which is showing SQLite data. For that I am using this select method:



public List<String> getAllProductsName(int id)
{

String buildSQL = "SELECT nome FROM " + DatabaseHelper.Produtos.TABELA + " WHERE id =" + id;


List<String> nomes = new ArrayList<String>();

SQLiteDatabase db = this.getDatabase();

Cursor cursor = database.rawQuery(buildSQL, null);

if (cursor.moveToFirst()) {
do {
nomes.add(cursor.getString(0));
} while (cursor.moveToNext());
}

return nomes;
}


The thing is, I am getting only the names but I need the ID as well. I know i could use "SELECT nome, _id FROM ", but how would I return that? Could i possibly return 2 lists (one with IDS and the other one with the Names) in the same method?


Or maybe I should create a new method that show the Names only (when i give the ID as a parameter)? Please help! thanks in advance! :)


Aucun commentaire:

Enregistrer un commentaire