sqlite查询 - 总是错过第一行 - android

时间:2014-07-16 15:14:37

标签: android android-activity android-sqlite

我构建了一个listview,显示来自sqllite的数据,它总是错过第一个sql行。如果我添加一个新行,它就不会显示该行(即使我重新启动应用程序,它也与更新无关) )。但如果我添加另一个新行,它将显示前一个“新”行。

感谢您的帮助

        Cursor resultSet = db.rawQuery("Select * from weight_listview ORDER BY `ID` DESC",null);
    resultSet.moveToFirst();


      final ListView listview = (ListView) findViewById(R.id.listView1);

    ////
    String[] columnames = new String[] {"C1", "C2", "C3"};
    int[] columnsR = new int[] {R.id.column1, R.id.column2, R.id.column3};


    int x=0; int fuPOINTER=0;
      final int[] fuID = new int[100];
    while(resultSet.moveToNext()){
        HashMap<String,String> map = new HashMap<String, String>();

        String d_weight = resultSet.getString(resultSet.getColumnIndex("weight"));
        String d_date = resultSet.getString(resultSet.getColumnIndex("date"));
        int d_id = resultSet.getInt(resultSet.getColumnIndex("ID"));
        fuID[fuPOINTER] = d_id;
        fuPOINTER++;

        x=0;
        map.put(columnames[x],d_weight);
        x++;
        map.put(columnames[x],d_date);
        x++;
        map.put(columnames[x],"i" + d_id);

        mylistData.add(map);
     }


         arrayAdapter = new SimpleAdapter(this, mylistData, R.layout.row,columnames , columnsR);
         listview.setAdapter(arrayAdapter);

1 个答案:

答案 0 :(得分:1)

if(resultset.moveToFirst()){//We have a result, do everything
   do{
      //get each row from resultset
   }while(resultSet.moveToNext());
}else{
   //We haven't data, show a toast
}