title: Deleting a row from recycler view and sqlite
body: <p>This is my adapter class:</p>
  
  <pre><code>public class adapter_cgpa extends RecyclerView.Adapter&lt;adapter_cgpa.Viewholder&gt; {
  
      ArrayList&lt;POJO&gt; cgpaArrayList;
  
  
      public adapter_cgpa(ArrayList&lt;POJO&gt; cgpaArrayList) {
          this.cgpaArrayList = cgpaArrayList;
      }
  
      @NonNull
      @Override
      public adapter_cgpa.Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  
          View listitem = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_cgpa, parent, false);
          return new Viewholder(listitem);
  
      }
  
      @Override
      public void onBindViewHolder(@NonNull adapter_cgpa.Viewholder holder, int position) {
  
          POJO cgpa= cgpaArrayList.get(position);
          holder.cname.setText(cgpa.getCname());
          holder.no_of_sems.setText(cgpa.getNo_of_sems());
          holder.cgpa.setText(cgpa.getCgpa());
          holder.percentage.setText(cgpa.getPercentage());
          holder.schemec.setText(cgpa.getSchemec());
  
  
      }
  
      @Override
      public int getItemCount() {
          return cgpaArrayList.size();
      }
  
      public class Viewholder extends RecyclerView.ViewHolder {
  
          TextView cname, no_of_sems, cgpa, percentage,schemec;
          ImageButton btndelete2;
  
  
          public Viewholder(@NonNull View itemView) {
              super(itemView);
  
              cname=(TextView)itemView.findViewById(R.id.name);
              no_of_sems=(TextView)itemView.findViewById(R.id.no_of_sem);
              cgpa=(TextView)itemView.findViewById(R.id.textView49);
              percentage=(TextView)itemView.findViewById(R.id.textView55);
              schemec=(TextView)itemView.findViewById(R.id.scheme2);
              btndelete2=(ImageButton)itemView.findViewById(R.id.btndelete2);
  
              btndelete2.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      final String snc = cname.getText().toString();
                      final String semrc = no_of_sems.getText().toString();
                      final String schc = schemec.getText().toString();
  
                      dbmanager db= new dbmanager(v.getContext());
                      db.delete2(snc,semrc,schc);
                  }
              });
  
          }
  
  
  
      }
  
  }
  </code></pre>
  
  <p>And this is my dbmanager class:</p>
  
  <pre><code>public class dbmanager extends SQLiteOpenHelper {
  
      String sgpa_table="create table Sgpa (sname text, semester text, sgpa  text,percent text, schemes text, primary key(sname,semester,schemes))";
      String cgpa_table="create table Cgpa (cname text, no_of_sems int, cgpa text, percentage text, schemec text, primary key(cname,no_of_sems,schemec))";
  
      public dbmanager(@Nullable Context context) {
          super(context, "Student", null, 1);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          db.execSQL(sgpa_table);
          db.execSQL(cgpa_table);
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
      }
  
  
  
      public Cursor fetch_data1() {
          SQLiteDatabase db = this.getWritableDatabase();
          String query = "Select*FROM Sgpa" ;
          Cursor cursor = db.rawQuery(query,null);
  
          return cursor;
      }
  
      public Cursor fetch_data2() {
          SQLiteDatabase db = this.getWritableDatabase();
          String query = "Select*FROM Cgpa" ;
          Cursor cursor = db.rawQuery(query,null);
  //        if (cursor != null) {
  //            cursor.moveToFirst();
  //        }
          return cursor;
  
      }
  
  
      public boolean delete2(String snc, String semrc, String schc){
          SQLiteDatabase db=this.getWritableDatabase();
          int result = db.delete("Cgpa", "cname= ? and no_of_sems = ? and schemec = ?", new String[] {snc, semrc, schc});
          return result &gt; 0;
      }
  
  }
  </code></pre>
  
  <p>This is not working. I think that instead of passing the value in textview, I need to pass the item position , that is, row id and column id but I don't know how to do that.                                            Can someone help me out with that?</p>