Reputation: 49
I have a ProgressBar, an EditText, Button and a TextView on my app layout. I set the Progressbar and TextView INVISIBLE by default. My Layout is like this Now I need to show the ProgressBar for 5 sec upon clicking the button, and then show the TextView. How to write java code for that?
I need to show the ProgressBar for 5 sec upon clicking the button, and then show the TextView.
Upvotes: 3
Views: 822
Reputation: 2819
You can use a Handler
like this:
final ProgressBar progressBar = findViewById(R.id.progressBar);
final TextView tv = findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
progressBar.setVisibility(View.GONE);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
tv.setVisibility(View.VISIBLE);
}
}, 0);
}, 5000); //5000 milliseconds = 5 sec
});
}
Upvotes: 2
Reputation: 842
on ButtonClick .
ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Your message");
progress.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
progress.dismiss();
}
},1000*5);
Upvotes: 3