title: Getting time value from timepicker - android
body: <p>There seems to be a lot of varied information on the net on how exactly to take the time entered on a timepicker by a user and do something with it. I want to take the user input time, save it to a variable and write to an SQLite Database. I can't figure out how to convert the TimePicker values into a variable that can be passed to the SQL database where it will be stored in a timestamp field. I'm open to alternative suggestions if this is not necessarily the best way to go about it. Thanks!</p>
  
  <p>This is my code so far:</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;RelativeLayout 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="10dp" &gt;
  
      &lt;TimePicker android:id="@+id/tpTimeStart"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginBottom="10dp" /&gt;
  
      &lt;Button android:id="@+id/btnUpdate"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Update" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Java:</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TimePicker;
  import android.widget.Button;
  import android.text.format.Time;
  import android.view.View;
  
  public class AddModule extends Activity {
  
      TimePicker tp1;
      Button bUpdate;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.add_module);
          bUpdate = (Button) findViewById(R.id.btnUpdate);
  
          bUpdate.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
          tp1 = (TimePicker)findViewById(R.id.tpTimeStart);
          Time timestart = tp1.getCurrentHour(), tp1.getCurrentMinute();
          }
          });
      }
  }
  </code></pre>