Reputation: 159
When I switch between my tabs the date won't show. I have searched for other methods for showing date with the help of textview but most of them didn't work. Only the method of thread worked for me but it has an issue that it doesn't show date in all tabs and the app goes down when we navigate from the navigation drawer.
My code:
Thread c = 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("dd MMM,yyyy");
String dateString =sdf.format(date);
tdate.setText(dateString);
}
});
}
}catch (InterruptedException a)
{
}
}
};
c.start();
`
Upvotes: 0
Views: 44