The problem is that I can not load in the database String expression from "00" to "09". Displays either 0 or 9. Here is the actual database creation code and the method of adding to it:

 @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE ALARMCLOCK (" + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + "HOURS TEXT, " + "MINUTES TEXT, " + "DAYS TEXT);"); } public static void insertAlarmCLock(SQLiteDatabase db, String hours, String minutes, String days){ ContentValues contentValues = new ContentValues(); contentValues.put("HOURS", hours); contentValues.put("MINUTES", minutes); contentValues.put("DAYS", days); db.insert("ALARMCLOCK", null, contentValues); } 

the addition itself:

 if(hours.getText().toString().isEmpty()){ h = "00"; } else { h = hours.getText().toString(); } if(minutes.getText().toString().isEmpty()){ min = "00"; } else { min = minutes.getText().toString(); } days = buffer.toString(); AlarmClockDB.insertAlarmClock(db, h, min, days); 

loading from DB:

 cursor = db.query("ALARMCLOCK", null, null, null, null, null, null); String[] from = new String[]{"HOURS", "MINUTES", "DAYS"}; int[] to = new int[]{R.id.hours, R.id.minutes, R.id.days}; adapter = new SimpleCursorAdapter(this, R.layout.list_item_layout, cursor, from, to, 0); listView.setAdapter(adapter); 
  • Here you have int[] to = new int[]{R.id.hours, R.id.minutes, R.id.days}; Integer , uniquely now your to without the second zeros will remain. - nick_n_a pm
  • It will remain to no zeros, it will appear on the screen - and you will think that zero is not saved in the database. - nick_n_a
  • @nick_n_a, and how does this relate to this? This is where the TextView IDs in the layout are defined, not the data itself. Or am I missing something? - Ivan
  • paradox, if you assign any character in front of the zeros, it displays the whole expression correctly, but just doesn’t want two zeros - Ivan
  • You have a problem with the conclusion! Change int [] to to string [] to at least - nick_n_a

2 answers 2

When translating from a String type to one of the integer types (for example, int), only a number is assigned to an int. So from 00 you get 0 , and from 09 - 9 .
View the file where your addition is located with if conditions. Specify the exact type of variables when determining h, min, days .

  • but I don’t actually have a translation from one type to another. All variables of type String , columns in a database of type TEXT - Ivan
  • The answer is ambiguous, from the area look for where the number is lost. Somewhere. - nick_n_a
  • @Ivan, you can see the data added to the table using sqlite3. Learn more at developer.android.com - Argetto

I used TimePicker, wrote my adapter, everything works.