How to turn a Cursor into a String?

Asked

Viewed 72 times

0

Hello, I need to figure out how to turn a Cursor with data coming from the Android Internal Database (Sqlite) into an Array of String or String.

I’ve tried it a few ways, but none of it worked.

String lista = "Lista de Compras \n\n";
for (int i = 0; i <= cursor.getColumnCount(); i++){
    lista.concat(cursor.getString(i)+ "\n");
}

And in the database:

public Cursor buscaListaProdutos(){
    SQLiteDatabase banco = getWritableDatabase();
    Cursor c = banco.rawQuery("SELECT _id, nomeProduto, qtdeProduto FROM listaProduto", null);

    if(c.moveToFirst()){
        banco.close();
        return c;
    }else{
        banco.close();
        return null;
    }
}
  • You need to do this manually or arrange a ORM that will do it for you. This type of operation is not done in such a simple or native way.

  • Friend is very simple.. see this post https://stackoverflow.com/questions/1354006/how-can-i-create-a-list-array-with-the-cursor-data-in-android

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.