Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package timer;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.TextView;
- import java.util.Timer;
- import java.util.TimerTask;
- public class MainActivity extends AppCompatActivity {
- int seconds=0;
- TextView textView;
- Timer timer = new Timer();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- MainActivity mojTimer = new MainActivity();
- textView = (TextView)findViewById(R.id.txtView);
- mojTimer.start();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- TimerTask timerTask = new TimerTask() {
- @Override
- public void run() {
- System.out.println(seconds++);
- try {
- textView = (TextView)findViewById(R.id.txtView);
- } catch (Exception ex){
- System.out.println(ex);
- }
- }
- };
- public void start(){
- timer.schedule(timerTask, 1000, 1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement