android - Time Doesn't update in TextView on every Button click.... What's the issue? -
time update first click... if click next time doesn't work. me... question end.
stack overflow want me type more details. question doesn't need more explanation
i don't know add can't type more long still want me type make code
java code :
package com.test.blog.timepicktest; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.textview; import java.util.calendar; public class mainactivity extends appcompatactivity { calendar c = calendar.getinstance(); textview tv; button btn; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); tv = (textview) findviewbyid(r.id.tv); btn = (button) findviewbyid(r.id.btn); btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { tv.settext(c.get(calendar.hour) + ":" + c.get(calendar.minute) + ":" + c.get(calendar.second)); } }); } }
xml file :
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.adiraimaji.blog.timepicktest.mainactivity"> <textview android:layout_width="174dp" android:layout_height="48dp" android:gravity="center" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" app:layout_constraintvertical_bias="0.268" tools:layout_editor_absolutex="82dp" android:id="@+id/tv" app:layout_constrainthorizontal_bias="0.501" /> <button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button" android:layout_margintop="8dp" android:layout_marginright="8dp" app:layout_constraintright_torightof="parent" android:layout_marginleft="8dp" app:layout_constraintleft_toleftof="parent" app:layout_constrainttop_tobottomof="@+id/tv" app:layout_constraintbottom_tobottomof="parent" android:layout_marginbottom="8dp" /> </android.support.constraint.constraintlayout>
c.get()
not update calendar date.
you must use calendar.getinstance().get(...)
when handle onclick
.
Comments
Post a Comment