1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SimpleAdapter show same data in while loop

Discussion in 'Programming/Internet' started by Mal Mmm, Sep 12, 2018.

  1. Mal Mmm

    Mal Mmm Guest

    I add many data to SQLite but my list view show last data inserted only. all rows have same value.

    public void onResume() {

    super.onResume();

    db = dbHelper.getWritableDatabase();

    String[] queryColumns = new String[]{"_id", DBHelper.COL_VEHICLE_TYPE, DBHelper.COL_OPTION_NAME,DBHelper.COL_DATE };

    cursor = db.query(DBHelper.TABLE_NAME, queryColumns, null,null,
    null,null,null);

    HashMap<String,String> map = new HashMap<String,String>();

    while(cursor.moveToNext())
    {

    map.put("vehicle_type", cursor.getString(1));
    map.put("date", cursor.getString(3));
    lst_driver.add(map);
    }

    String[] showColumns = new String[]{"vehicle_type", "date"};
    int[] views = new int[] {R.id.ColType, R.id.ColDate};

    adapter = new SimpleAdapter(DriverActivity.this,lst_driver, R.layout.activity_list_layout, showColumns, views);
    lv_driver.setAdapter(adapter);
    }


    when I run this app it show last DBHelper.COL_VEHICLE_TYPE and DBHelper.COL_DATE after I insert to SQLi like this.

    0
    9-12-2018
    0
    9-12-2018
    0
    9-12-2018
    0
    9-12-2018


    I don't use any update table function in my code. It should show all data from SQLite that are not same values . How should i fix it?

    Login To add answer/comment
     

Share This Page