Time Doesn’t update in TextView on every Button click… What’s the issue?

Home / Uncategorized / Time Doesn’t update in TextView on every Button click… What’s the issue?

Question:
Time just update for first click… If I click next time It doesn’t work. Help me… Question end.

Stack overflow want me to type more details. But this question doesn’t need more explanation

I don’t know what to add I can’t type more for this long it still want me to type something to make the code

Java Code :package com.test.blog.timepicktest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {

Calendar c = Calendar.getInstance();
TextView tv;
Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv.setText(c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND));
}
});

}

}
XML File :

Leave a Reply

Your email address will not be published. Required fields are marked *