Reputation: 61
I am just wondering if it is possible to change to another activity, after a checkbox has been ticked, and once its ticked it goes to that activity after 5 seconds or loads something that says please wait then changes. And if that activity has been returned to the checkbox is not checked anymore.
I havent got any code because i was just reading around documentation and havent found anything so just want to know if anyone has done something similar and if they could share please?
Thanks!
Upvotes: 0
Views: 423
Reputation: 7917
checkBox.setChecked(false); //put this in onResume() or onCreate() or something
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(i);
FirstActivity.this.finish();
}
}, 5000); //wait for 5 seconds
}
}
});
Upvotes: 1
Reputation: 6813
It seems that you may want to do this either in onCheckListener or the onClickListener and start the next activity with startActivity(intent)
If you need to delay the you may want to use a Handler.postDelayed
method but not entirely sure If I understood your workflow so please try to explained it a bit more detail.
Upvotes: 1