dimanche 27 mars 2016

How I can use HasMap with variables? Java sqlite

I have two variables(nom and marc) that come from database(sqlite). I need to show these variables with HasMap. I try this but It does not work.

private void  populateList(String nom, String marc){
    list = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> temp = new HashMap<String, String>();
    temp.put(FIRST_COLUMN, nom);
    temp.put(SECOND_COLUMN, marc);
    temp.put(THIRD_COLUMN, "1");
    list.add(temp);
}

what am I doing wrong?

In a click event of a button I use a cursor to fetch data from the database.

Cursor c = db.rawQuery("Select * from prod where id_prod = " + id, null);
            if (c.moveToFirst()){
                do {
                    String nom = c.getString(1);
                    String marc = c.getString(2);

                    populateList(nom, marc);

                } while(c.moveToNext());
            }

As you can see PopulateList is a method different from the button then I need to send the variables. Maybe that I am doing wrong. Any answer will help. Thanks

Aucun commentaire:

Enregistrer un commentaire