Note that there are some explanatory texts on larger screens.

plurals
  1. POTimePicker Saves Zero Value in SQLite Database
    primarykey
    data
    text
    <p>I have a TimePicker which I'd like to use to determine a length of time a user can stay connected. Lets say the time now is 10:00 if the user selects 11:00 - I'd like the source code below to determine that there are 60 minutes between the current time - and the time selected and set that to a string/long (minutes) which I then have displayed as a textview. </p> <p>I've coded everything as I thought it should be - however the textview never seems to update with minutes value. Everytime I attempt to view the data - I get a value of 0 not matter what the timepicker is set to.</p> <p>Anyone have any suggestions? I'm stumped at the moment and I'm not sure what else to try. </p> <p>ADDEDITDEVICE.JAVA (where the timepicker and minutes determination takes place)</p> <pre><code>public class AddEditDevice extends Activity { private long rowID; private EditText nameEt; private EditText capEt; private EditText codeEt; private TimePicker timeEt; private TextView ssidTextView; Date date = new Date(); TimePicker tp; // @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_country); WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); String ssidString = info.getSSID(); if (ssidString.startsWith("\"") &amp;&amp; ssidString.endsWith("\"")){ ssidString = ssidString.substring(1, ssidString.length()-1); //TextView ssidTextView = (TextView) findViewById(R.id.wifiSSID); ssidTextView = (TextView) findViewById(R.id.wifiSSID); ssidTextView.setText(ssidString); nameEt = (EditText) findViewById(R.id.nameEdit); capEt = (EditText) findViewById(R.id.capEdit); codeEt = (EditText) findViewById(R.id.codeEdit); timeEt = (TimePicker) findViewById(R.id.timeEdit); Bundle extras = getIntent().getExtras(); if (extras != null) { rowID = extras.getLong("row_id"); nameEt.setText(extras.getString("name")); capEt.setText(extras.getString("cap")); codeEt.setText(extras.getString("code")); String time = extras.getString("time"); String[] parts = time.split(":"); timeEt.setCurrentHour(Integer.valueOf(parts[0])); timeEt.setCurrentMinute(Integer.valueOf(parts[1])); timeEt.setIs24HourView(false); date.setMinutes(tp.getCurrentMinute()); date.setHours(tp.getCurrentHour()); Long.toString(minutes); } Button saveButton =(Button) findViewById(R.id.saveBtn); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (nameEt.getText().length() != 0) { AsyncTask&lt;Object, Object, Object&gt; saveContactTask = new AsyncTask&lt;Object, Object, Object&gt;() { @Override protected Object doInBackground(Object... params) { saveContact(); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; saveContactTask.execute((Object[]) null); } else { AlertDialog.Builder alert = new AlertDialog.Builder(AddEditDevice.this); alert.setTitle(R.string.errorTitle); alert.setMessage(R.string.errorMessage); alert.setPositiveButton(R.string.errorButton, null); alert.show(); } } });} } long minutes = ((new Date()).getTime() - date.getTime()) / (1000 * 60); private void saveContact() { DatabaseConnector dbConnector = new DatabaseConnector(this); if (getIntent().getExtras() == null) { // Log.i("Test for Null", ""+dbConnector+" "+nameEt+" "+capEt+" "+timeEt+" "+codeEt+" "+ssidTextView); dbConnector.insertContact(nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString() + ":" + timeEt.getCurrentMinute().toString(), codeEt.getText().toString(), Long.toString(minutes), ssidTextView.getText().toString()); } else { dbConnector.updateContact(rowID, nameEt.getText().toString(), capEt.getText().toString(), timeEt.getCurrentHour().toString() + ":" + timeEt.getCurrentMinute().toString(), codeEt.getText().toString(), Long.toString(minutes), ssidTextView.getText().toString()); } } } </code></pre> <p>VIEW COUNTRY.JAVA (where the minutes data set by the timepicker should be visible)</p> <pre><code>public class ViewCountry extends NfcBeamWriterActivity { private static final String TAG = ViewCountry.class.getName(); protected Message message; NfcAdapter mNfcAdapter; private static final int MESSAGE_SENT = 1; private long rowID; private TextView nameTv; private TextView capTv; private TextView codeTv; private TextView timeTv; private TextView ssidTv; private TextView combined; private TextView minutes; //String timetest = "300"; // String a="\""; // String b="\""; // String message1 = a + ssidTv.getText().toString() +"," + // capTv.getText().toString()+b; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_country); SharedPreferences prefs=getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor=prefs.edit(); editor.putBoolean("name", true); editor.putBoolean("cap", true); editor.putBoolean("code", true); editor.putBoolean("time", true); editor.putBoolean("ssid",true); editor.putBoolean("minutes",true); editor.putBoolean("timetest",true); editor.commit(); setDetecting(true); startPushing(); setUpViews(); Bundle extras = getIntent().getExtras(); rowID = extras.getLong(CountryList.ROW_ID); } private void setUpViews() { nameTv = (TextView) findViewById(R.id.nameText); capTv = (TextView) findViewById(R.id.capText); timeTv = (TextView) findViewById(R.id.timeEdit); codeTv = (TextView) findViewById(R.id.codeText); ssidTv = (TextView) findViewById(R.id.wifiSSID); minutes = (TextView) findViewById(R.id.Minutes); } @Override protected void onResume() { super.onResume(); new LoadContacts().execute(rowID); } private class LoadContacts extends AsyncTask&lt;Long, Object, Cursor&gt; { DatabaseConnector dbConnector = new DatabaseConnector(ViewCountry.this); @Override protected Cursor doInBackground(Long... params) { dbConnector.open(); return dbConnector.getOneContact(params[0]); } @Override protected void onPostExecute(Cursor result) { super.onPostExecute(result); result.moveToFirst(); int nameIndex = result.getColumnIndex("name"); int capIndex = result.getColumnIndex("cap"); int codeIndex = result.getColumnIndex("code"); int timeIndex = result.getColumnIndex("time"); int ssidIndex = result.getColumnIndex("ssid"); nameTv.setText(result.getString(nameIndex)); capTv.setText(result.getString(capIndex)); timeTv.setText(result.getString(timeIndex)); codeTv.setText(result.getString(codeIndex)); ssidTv.setText(result.getString(ssidIndex)); result.close(); dbConnector.close(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.view_country_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.editItem: Intent addEditContact = new Intent(this, AddEditDevice.class); // addEditContact.putExtra(CountryList.ROW_ID, rowID); // addEditContact.putExtra("name", nameTv.getText()); // addEditContact.putExtra("cap", capTv.getText()); // addEditContact.putExtra("code", codeTv.getText()); startActivity(addEditContact); return true; case R.id.user1SettingsSave: Intent Tap = new Intent(this, Tap.class); startActivity(Tap); return true; case R.id.deleteItem: deleteContact(); return true; default: return super.onOptionsItemSelected(item); } } private void deleteContact() { AlertDialog.Builder alert = new AlertDialog.Builder(ViewCountry.this); alert.setTitle(R.string.confirmTitle); alert.setMessage(R.string.confirmMessage); alert.setPositiveButton(R.string.delete_btn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int button) { final DatabaseConnector dbConnector = new DatabaseConnector( ViewCountry.this); AsyncTask&lt;Long, Object, Object&gt; deleteTask = new AsyncTask&lt;Long, Object, Object&gt;() { @Override protected Object doInBackground(Long... params) { dbConnector.deleteContact(params[0]); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; deleteTask.execute(new Long[] { rowID }); } }); alert.setNegativeButton(R.string.cancel_btn, null).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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