Android sqlite: how to retrieve specific data from particular column?

后端 未结 9 2082
生来不讨喜
生来不讨喜 2020-12-31 18:17

I am developing restaurant menu application. My app has a sqlite table which has these columns:

\"id\", \"category\", \"item_name\"

Content

相关标签:
9条回答
  • 2020-12-31 18:51
    String query = "SELECT item_name FROM todo WHERE category =" + vg ;
    Cursor  cursor = database.rawQuery(query,null);
    if (cursor.moveToFirst()) {
             while (cursor.isAfterLast() != true) {
               string itemname =  cursor.getString(cursor.getColumnIndex("item_name")));
              }
    }
    

    Here moveToFirst checks if there are items satisfying the criteria and then loops through cursor using while loop. The string itemname can be replaced by list adaper to populate the data. Hope this helps.

    0 讨论(0)
  • 2020-12-31 18:59
    String query = "SELECT * FROM Table_Name WHERE Col_Name='name'";
    Cursor cursor = mDb.rawQuery(query, null);
    
    0 讨论(0)
  • 2020-12-31 18:59
    public List<String> getAllData(String email)
    {
        db = this.getReadableDatabase();
        String[] projection = {email};
    
        List<String> list = new ArrayList<>();
    
       Cursor cursor = db.query(Table_name,null,"email=?",projection,null,null,null,null);
    
      //  cursor.moveToFirst();
    
        if(cursor.moveToFirst()) {
            do {
    
                list.add(cursor.getString(cursor.getColumnIndex("id")));
                list.add(cursor.getString(cursor.getColumnIndex("name")));
                list.add(cursor.getString(cursor.getColumnIndex("email")));
                list.add(cursor.getString(cursor.getColumnIndex("password")));
               // cursor.moveToNext();
    
            } while (cursor.moveToNext());
        }
        return list;
    }
    
    0 讨论(0)
提交回复
热议问题