Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to remove item from RecyclerView DataBase Sqlite helper class(RecyclerView)

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4.22k
    Comment on it

    Here I have created a method in DataBase helper(sqlite) to remove Items from RecyclerView. In the example code first i have created deleteCallDetail method and after then In Adpter class I have used ClickListener, so that when we click on cross(Image)item that item will be removed from the RecyclerView list.

    Step(1)- Create query for remove item in DataBase Helper(sqlite)

     public void deleteCallDetail(String number, String duration) {
            SQLiteDatabase db = this.getWritableDatabase();
            db.delete(TABLE_NAME, "CallNumber='" + number + "'and CallDuration='" + duration + "'", null);
            db.close();
        }
    

    Step(2)Database Helper remove item Method call-

     holder.cross.setOnClickListener(new AdapterView.OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                    // mListner.OnRemoveClick(position);
                    DatabaseHelper databaseHelper = new DatabaseHelper(v.getContext());
                    databaseHelper.deleteCallDetail(callData.getPhNumber(), callData.getCallDuration());
                    callDataList.remove(position);
                    notifyDataSetChanged();
                }
            });
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: