Check if record exist in the database android

后端 未结 3 438
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-23 03:53

I want to check if records exist in the SQLite database, here\'s what I have done so far. when I search for a already existing records im getting value from EditText in list.

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-23 04:27

    DatabaseManager.java

    public Cursor checkFavourites()
    {
    
        String query="select * from "+DATABASE_TABLE;
        Cursor cursor=db.rawQuery(query,null);
    
        return cursor;
    }
    

    MainActivity.java

    public void favourite_Click(View view){
        Cursor cursor=dbManager.checkFavourites();
        if (cursor.getCount()>0)
        {
            Toast.makeText(MainActivity.this, "Favourites", Toast.LENGTH_SHORT).show();
        }
        else
        {
            Toast.makeText(MainActivity.this,"Nothing in favourites yet", Toast.LENGTH_SHORT).show();
        }
    }
    

提交回复
热议问题