java - get total hours from two timepicker -
can tell me how can total hours 2 timepicker ?it possible since 2 timepicker getting same function.
workdetails.java
edittext timein = (edittext) findviewbyid(r.id.edittext6); edittext timeout = (edittext) findviewbyid(r.id.edittext7); timein.setonfocuschangelistener(new view.onfocuschangelistener() { @override public void onfocuschange(view v, boolean hasfocus) { if (hasfocus) { timepick time = new timepick(v); fragmenttransaction ft = getfragmentmanager().begintransaction(); time.show(ft, "timepicker"); } } }); timeout.setonfocuschangelistener(new view.onfocuschangelistener(){ @override public void onfocuschange(view v,boolean hasfocus) { if (hasfocus) { timepick time = new timepick(v); fragmenttransaction ft = getfragmentmanager().begintransaction(); time.show(ft, "timepicker"); } } });
timepick.java
public class timepick extends dialogfragment implements timepickerdialog.ontimesetlistener { edittext time; public timepick(view view) { time=(edittext)view; } public dialog oncreatedialog(bundle savedinstancestate) { final calendar c= calendar.getinstance(); int hour=c.get(calendar.hour_of_day); int minute=c.get(calendar.minute); return new timepickerdialog(getactivity(),this,hour,minute, dateformat.is24hourformat(getactivity())); } public void ontimeset(timepicker view,int hourofday, int minute) { time.settext(integer.tostring(hourofday) + ":" + integer.tostring(minute)); } }
workdetails.xml
<edittext android:layout_width="140dp" android:layout_height="wrap_content" android:id="@+id/edittext6" android:layout_x="147dp" android:layout_y="170dp" android:hint="select time" android:clickable="true"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="time in" android:id="@+id/textview7" android:layout_x="23dp" android:layout_y="184dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="time out" android:id="@+id/textview8" android:layout_x="23dp" android:layout_y="247dp" /> <edittext android:layout_width="143dp" android:layout_height="wrap_content" android:id="@+id/edittext7" android:layout_x="147dp" android:layout_y="241dp" android:hint="select time"/>
you can calculate hours of day concat time hours , min (.) dot >> later parse float >> , make differance. here working code snippet.
float end = float.parsefloat("21.00"); float start = float.parsefloat("10.00"); system.out.println(end-start);
change method like:
public void ontimeset(timepicker view,int hourofday, int minute) { time.settext(integer.tostring(hourofday) + "." + integer.tostring(minute)); }
and value later edittext.gettext();
edit:
make timein
edittext variable static , value of while setting timeout this..
public void ontimeset(timepicker view,int hourofday, int minute) { time.settext(integer.tostring(hourofday) + "." + integer.tostring(minute)); if(time.getid==r.id.edittext7){ if(youractivity.timein !=null){ string timein = youractivity.timein.gettext().tostring(); float end = float.parsefloat(time.gettext().tostring); float start = float.parsefloat(timein); system.out.println(end-start); // need calculated hours } } }
Comments
Post a Comment