Saturday, December 11, 2021

Current Time show in android

 Xml:-

<TextView
android:layout_width="match_parent"
android:textSize="20dp"
android:id="@+id/date"
android:layout_height="wrap_content"
android:text="hello world" />








Java :- 

Thread t = new Thread() {
@Override
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView tdate = (TextView) findViewById(R.id.date);
long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy\nhh-mm-ss a");
String dateString = sdf.format(date);
tdate.setText(dateString);
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();

No comments:

Post a Comment

Activity Navigation One Activity to another Activity

Main Activity :-   <? xml version ="1.0" encoding ="utf-8" ?> < RelativeLayout xmlns: android ="http://sch...