Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would store the value as an number in SQLite to make it compatible since SQLite doesn't have built in date/time data types.</p> <p>You will want to save the value in the DatePicke's <code>OnDateSetListener</code>.</p> <p>To give you an example on how to do this is exactly depends largely on how you create the date pickers. Assuming the values are set you can use the code below. Note that it assumes tvData and tvHora are in class properties (global variables to the class), this way you can reuse them once you set them (which should be done in onCreate) Perhaps something like this would work:</p> <pre><code>private final SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //keep your current code for the date/time pickers.. public void saveData(View button) { String dateStr = tvData.getText().toString(); String timeStr = tvHora.getText().toString(); //only save if both fields are non empty if (!TextUtils.isEmpty(dateStr) &amp;&amp; !TextUtils.isEmpty(timeStr)) { try { Date d = parser.parse(dateStr + " " + timeStr); ContentValues valor = new ContentValues(); valor.put("mensagenssalvas", d.getTime()); db.insert("mensagens", null, valor); } catch(ParseException ex) { Log.e("YOURTAG", "Error parsing date", ex); } } else { Log.d("YOURTAG", "Both fields not present, can't save"); } } </code></pre> <p>In your xml layout for the file make a save button like this:</p> <pre><code>&lt;Button android:id="@+id/Save" android:onClick="saveData" android:text="Save" /&gt; </code></pre> <p>Or if you don't want to put the onClick in xml, you can do the same thing in code like this:</p> <pre><code>Button saveButton = findViewById(R.id.save); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View button) { saveData(button); } }); </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