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