Program to show time and update every second in android
 
package com.chitraksh.tutorial.now;

import java.util.Date;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class Now extends Activity implements View.OnClickListener{
	Button btn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_now);
		btn=(Button)findViewById(R.id.button);
		btn.setOnClickListener(this);
		updateTime();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.now, menu);
		return true;
	}
	private void updateTime() {
		btn.setText(new Date().toString());
		}
	@Override
	public void onClick(View v) {
		updateTime();
		
	}

}
share on whatapp
210 Views

Comments

117.247.169.7time and update every second in android
 
 
Private Policy   Terms of Service   4922