1
Good afternoon guys, I have a problem with my project. I have a Listview that receives information from Cursor and then sends it to the Adapter, but it is only pulling a record from my database, you could help me ?
public void lprod(SQLiteDatabase db){
    ArrayList<modelListprod> prod = new ArrayList<modelListprod>();
    listprod = new modelListprod();
    String descricao = "";
    String ean = "";
    String status = "";
    Double precoprod;
    String categoria;
    int cod;
    SQLiteDatabase d5 = dadosOpenHelper.getReadableDatabase();
    Cursor cursor5 = d5.query("produto" , new String[]{"descricao", "ean", "status", "precoprod", "codigocateg", "cod"},null, null, null   ,null,null,null);
   if (cursor5 != null) {
       if (cursor5.moveToFirst()) {
           do {
               descricao = cursor5.getString(0);
               ean = cursor5.getString(1);
               status = cursor5.getString(2);
               precoprod = cursor5.getDouble(3);
               categoria = cursor5.getString(4);
               cod = cursor5.getInt(5);
               listprod.setDescricao(descricao);
               listprod.setCategoria(categoria);
               listprod.setEan(ean);
               listprod.setPreco(precoprod);
               listprod.setStatus(status);
               listprod.getId(cod);
               //listadeprod.add(listprod);
           } while (cursor5.moveToNext());
       }
   }
    listadeprod.add(listprod);
    AdapterProd adapterProd = new AdapterProd(this, listadeprod);
    listproduto.setAdapter(adapterProd);
}
						
How many listprod are you creating? How often are you adding a listprod to the array?
– ramaral
listprod it sends the information to the adapter Model, the variable reading the listview is the listproduct, and the listprod it is only adding 1 time.
– Dev
So it’s explained because the list only has one.
– ramaral
However the listprod it is placed only once, why it sends the database information to the modelListProd and through this model it talks with the layout of listr_products to fit the database data in its proper places. If I repeat or put some condition in it does not work.
– Dev