android - Get TimePicker Current Time on Button Click -


friends new on android app developing. have completed app.

in last stage, i'm facing difficulties , trying last 3 days solve not.

i need current hour , minutes time picker (without dialog) when user clicks button. want save data database on button click.

would please me providing xml , java file below.

xml:

<relativelayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="com.example.timepicker.mainactivity" >      <timepicker         android:id="@+id/timepicker"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_margintop="21dp" />      <button         android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/timepicker1"         android:layout_centerhorizontal="true"         android:layout_margintop="77dp"         android:text="button" />  </relativelayout> 

java:

package com.example.timepicker;  import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.menu; import android.view.menuitem;  public class mainactivity extends actionbaractivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);      }      @override     public boolean oncreateoptionsmenu(menu menu) {          // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();         if (id == r.id.action_settings) {             return true;         }         return super.onoptionsitemselected(item);     } } 

using calendar instance can current hour , minutes-

calendar c; private int mhour; private int mminute; 

initialize -

c = calendar.getinstance(); mhour = c.get(calendar.hour); mminute = c.get(calendar.minute);  // current hour , minutes of device time  

also refer calendar


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -