in the table mytable (id, resh, text) you need to delete the record by dResh entered in the first case, in the second case by dText.

this entry deletes everything ok

case R.id.btnDel: db.delete("mytable", "resh" + "='" + dResh + "'", null); break; 

and on this 0 reaction

 case R.id.btnDel2: db.delete("mytable", "text" + "='" + dText + "'", null); break; 

here is given dText

 spinner_text.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // показываем позиция нажатого элемента(в переменную реш заносится значение выбранного элемента) dText = spinner_text.getSelectedItem().toString(); System.out.println(dText); } 

base

 public class DBHelper extends SQLiteOpenHelper { public static final String TABLE = "mytable"; final String LOG_TAG = "логи"; public DBHelper(Context context) { // конструктор суперкласса super(context, "myDB", null, 1); } @Override public void onCreate(SQLiteDatabase db) { Log.d(LOG_TAG, "--- база создана ---"); // создаем таблицу с полями db.execSQL("create table "+TABLE+" (" + "id integer primary key autoincrement," + "resh text," + "text text" + ");"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } public ArrayList<String> getAllProvinces(){ ArrayList<String> list=new ArrayList<String>(); SQLiteDatabase db = this.getReadableDatabase(); db.beginTransaction(); try { String selectQuery = "SELECT * FROM "+ TABLE; Cursor cursor = db.rawQuery(selectQuery, null); if(cursor.getCount() >0) { while (cursor.moveToNext()) { // Add province name to arraylist String resh= cursor.getString(cursor.getColumnIndex("resh")); list.add(resh); } } db.setTransactionSuccessful(); } catch (SQLiteException e) { e.printStackTrace(); } finally { db.endTransaction(); // End the transaction. db.close(); // Close database } return list; } 

}

  • Because records differ only in resh / text and dResh / dText, then you must assume that something is wrong with your dText. - Yuriy SPb
  • made a conclusion in logcat displays exactly what you need - Alexey Fedorov
  • In this case, you describe an impossible situation. I can only advise you to turn off the InstantRun in the studio and restart it and the computer and all that is possible. Well, or try not to take the values ​​from the spinner, but manually prescribe ... Somewhere you have an error, but you cannot see it in the code above - YuriySPb
  • maybe it's something in the base settings? I am confused by one entry - Alexey Fedorov

3 answers 3

the whole thing is inattention

  btnDel2 = (Button) findViewById(R.id.btnDel2); btnDel2.setOnClickListener(this); 

and it was

  btnDel2 = (Button) findViewById(R.id.btnDel2); btnDel.setOnClickListener(this); 

    Try instead of SQLiteDatabase db = this.getReadableDatabase(); write SQLiteDatabase db = this.getWritableDatabase()

      To delete a table row, use LIKE, not a comparison of the lines in the forehead, but:

      db.delete ("mytable", "text" + "LIKE '%" + dText + "%'", null);