Use a thread, loop inside that thread. Use runOnUiThread to update your text value (can't be done in worker thread).
boolean keepRunning = true;
Thread thread = new Thread(){
@Override
public void run(){
while(keepRunning){
// make the thread wait half a second (if you're only showing time up to seconds, it doesn't need to be updating constantly)
try{
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable(){
@Override
public void run(){
TextView time = (TextView) findViewById(R.id.time);
time.setText(DateUtils.formatDateTime(getBaseContext(), System.currentTimeMillis(),DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_12HOUR));
}
});
}
}
};
thread.start();
set keepRunning to false before exiting your app to stop the thread.