title: Remove item from database in recyclerview
body: <p>I would like to add a feature that would allow me to remove a row from my recyclerview/database.</p>
  
  <p>This feature is integrate to each item of my recyclerview as show in the following picture :  </p>
  
  <p><a href="https://i.stack.imgur.com/Hwm04.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hwm04.png" alt="enter image description here"></a></p>
  
  <p><strong>MySQLite.java:</strong></p>
  
  <pre><code>public class MySQLite extends SQLiteOpenHelper {
  
  private static final String DATABASE_NAME = "character";
  private static final int DATABASE_VERSION = 1;
  private static final String CHARACTER_TABLE = "Ichar";
  private static final String CHAR_TABLE = "create table " + CHARACTER_TABLE + "(id INTEGER PRIMARY KEY AUTOINCREMENT, nom TEXT, prenom TEXT , numero TEXT)";
  
  
  Context context;
  
  
  public MySQLite(Context context) {
      super(context, DATABASE_NAME, null, DATABASE_VERSION);
      this.context = context;
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
  
      db.execSQL(CHAR_TABLE);
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
      onCreate(db);
  }
  
  
  public void InsererBDD(String nom, String prenom, String numero) {
  
      Log.d("insert", "before insert");
  
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues entree = new ContentValues();
      entree.put("nom", nom);
      entree.put("prenom", prenom);
      entree.put("numero", numero);
  
      db.insert(CHARACTER_TABLE, null, entree);
  
      db.close();
      Toast.makeText(context, "insérer entrée", Toast.LENGTH_LONG);
  
      Log.i("insert", "after insert");
      db.close();
  }
  
  
  public List&lt;Character&gt; donneesBDD() {
  
      List&lt;Character&gt; modelList = new ArrayList&lt;Character&gt;();
      String query = "select * FROM " + CHARACTER_TABLE;
  
      SQLiteDatabase db = this.getWritableDatabase();
  
      Cursor cursor = db.rawQuery(query, null);
  
      if (cursor.moveToFirst()) {
          do {
              Character model = new Character();
              model.setCharacter_Id(cursor.getInt(0));
              model.setNom(cursor.getString(1));
              model.setPrenom(cursor.getString(2));
              model.setNumero(cursor.getString(3));
  
              modelList.add(model);
  
          } while (cursor.moveToNext());
      }
  
      Log.d("donnee character", modelList.toString());
  
  
      return modelList;
  
  }
  
  public void supprimerLigne(int character_Id){
  
      SQLiteDatabase db = getWritableDatabase();
      db.delete(CHARACTER_TABLE , "id" + " = ?", new String[] { String.valueOf(character_Id)});
      db.close();
  
  }
  
  public Character getCharacterById(int Id) {
  
      SQLiteDatabase db = getWritableDatabase();
      String query = "SELECT  " +
              "nom" + "," +
              "prenom" + "," +
              "numero" +
              " FROM  " + CHARACTER_TABLE
              + " WHERE  " +
              "id" + "=?";
  
      Character character = new Character();
  
  
      Cursor cursor = db.rawQuery(query, new String[]{String.valueOf(Id)});
  
      if (cursor.moveToFirst()) {
          do {
              character.character_Id = cursor.getInt(cursor.getColumnIndex("id"));
              character.nom = cursor.getString(cursor.getColumnIndex("nom"));
              character.prenom = cursor.getString(cursor.getColumnIndex("prenom"));
              character.numero = cursor.getString(cursor.getColumnIndex("numero"));
  
          } while (cursor.moveToNext());
  
  
  
      }
      cursor.close();
      db.close();
      return character;
  
  }
  }
  </code></pre>
  
  <p><strong>MyAdapter.java:</strong></p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.MyViewHolder&gt; {
  
  static List&lt;Character&gt; characters;
  static Context context;
  
  MyAdapter(Context context,List&lt;Character&gt; characters)
  {
  
      this.characters = new ArrayList&lt;Character&gt;();
      this.context = context;
      this.characters = characters;
  
  }
  
  @Override
  
      public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int itemType) {
      View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
              R.layout.list_cell, null);
  
  
      MyViewHolder myViewHolder = new MyViewHolder(itemLayoutView);
      return myViewHolder;
  }
  
  @Override
  public void onBindViewHolder(MyAdapter.MyViewHolder holder, int position) {
      holder.nom.setText(characters.get(position).getNom());
      holder.prenom.setText(characters.get(position).getPrenom());
  }
  
  
  @Override
  public int getItemCount() {
      return characters.size();
  }
  
  public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnCreateContextMenuListener,View.OnClickListener, MenuItem.OnMenuItemClickListener {
  
      public TextView nom;
      public TextView prenom;
      public ImageButton delete;
  
  
  
  
  
  
      public MyViewHolder(final View itemLayoutView) {
          super(itemLayoutView);
  
  
          nom = ((TextView) itemLayoutView.findViewById(R.id.nom));
          prenom = ((TextView) itemLayoutView.findViewById(R.id.prenom));
          delete = (ImageButton) itemView.findViewById(R.id.delete);
          itemLayoutView.setOnClickListener(this);
          itemLayoutView.setOnCreateContextMenuListener(this);
  
  
          delete.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  MySQLite sqlite = new MySQLite(context);
                  sqlite.supprimerLigne(getAdapterPosition());
  
                  }
  
          });
  
      }
          @Override
              public void onClick(View view) {
  
              Intent intent = new Intent(context, personne.class);
              Bundle extras = new Bundle();
              extras.putInt("position", getAdapterPosition());
              intent.putExtras(extras);
              context.startActivity(intent);
  
              Toast.makeText(MyAdapter.context, "Vous avez sélectionné un item" + getAdapterPosition(), Toast.LENGTH_LONG).show();
  
          }
  
  
  
      @Override
      public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
  
  
          menu.setHeaderTitle("");
          menu.add(0, v.getId(), 0, "Modifier Contact");
          menu.add(0, v.getId(), 0, "Supprimer Contact");
      }
  
      @Override
      public boolean onMenuItemClick(MenuItem item)
      {
  
  
  
          return true;
      }
  }
  
  }
  </code></pre>
  
  <p>can you guide me?</p>
  
  <p>Thanks a lot.</p>