Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save Data and Time from TextView to SQLite?
    primarykey
    data
    text
    <p>In my app I have 2 buttons which opens a Time Dialog/Date Dialog and then I select the date and time and then press OK. Thefore the value gets shown in a TextView (for each one), so I need to get the VALUE from the TextViews and save it in the database.</p> <p><strong>database row</strong> = <code>date</code></p> <p>Code for Time shown in TextView: </p> <pre><code>tvHora = (TextView) findViewById(R.id.tvHora); final Calendar d = Calendar.getInstance(); hour = d.get(Calendar.HOUR_OF_DAY); minute = d.get(Calendar.MINUTE); //set current time into textview tvHora.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute))); </code></pre> <p>Code for Date shown in TextView: </p> <pre><code>tvData = (TextView) findViewById(R.id.tvData); final Calendar c = Calendar.getInstance(); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); day = c.get(Calendar.DAY_OF_MONTH); //SET CURRENT DATE INTO TEXTVIEW tvData.setText(new StringBuilder().append(year).append("-").append(month + 1).append("-").append(day).append("-")); </code></pre> <p>Code when I click the SAVE button: </p> <pre><code> ContentValues valor = new ContentValues(); valor.put("mensagenssalvas", resultado); db.insert("mensagens", null, valor); </code></pre> <p>So how do I get the values from the textviews to save in the database?</p> <p><strong>EDIT</strong> TimePicker Dialog: </p> <pre><code>private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int selectedHour, int selectedMinute) { // TODO Auto-generated method stub hour = selectedHour; minute = selectedMinute; //set current time into textview tvHora.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute))); } }; </code></pre> <p>DatePicker Dialog: </p> <pre><code> private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int Year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub year = Year; month = monthOfYear; day = dayOfMonth; // set selected date into textview tvData.setText(new StringBuilder().append(month + 1) .append("-").append(day).append("-").append(year) .append(" ")); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload