Reputation:
I have this code below: when you tick the checkbox
, a spinner
, button
and the checkbox
disappear.
But when I run the app and tick the checkbox
, the checkbox
sort of just disappears without showing the 'tick' in the box? Is there a way to make it so I can see the box with the tick, then the elements sort of fade out?
Thanks!
Code:
newCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// makes the set disappear when checkbox is ticked.
newCheckbox.setVisibility(View.GONE);
newButton.setVisibility(View.GONE);
spinner.setVisibility(View.GONE);
}
});
Upvotes: 1
Views: 302
Reputation: 46
You can set checkbox is checked(ticked) or not manually before disappearing checkbox.
newCheckbox.setChecked(isChecked); //isChecked = Checkbox clicked && !isChecked = checkbox not clicked
Upvotes: 0
Reputation: 196
You can try using a TimerTask and handler for this. Which will change the Checkbox's VISIBILITY
after a delay you mention.
Example code:
newCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// makes the set disappear when checkbox is ticked.
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// this code will be executed after 2 seconds
newCheckbox.setVisibility(View.GONE);
newButton.setVisibility(View.GONE);
spinner.setVisibility(View.GONE);
}
}, 2000);
}
});
So your Views will fade out after 2 seconds. You can set the milliseconds as per your requirement.
Upvotes: -1
Reputation: 1043
Try this,
newCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// makes the set disappear when checkbox is ticked.
newCheckBox.setVisibility(View.VISIBLE);
newButton.setVisibility(View.VISIBLE);
spinner.setVisibility(View.VISIBLE);
newCheckBox.animate().alpha(0.0f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
newCheckBox.setVisibility(View.GONE);
}
});
newButton.animate().alpha(0.0f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
newButton.setVisibility(View.GONE);
}
});
spinner.animate().alpha(0.0f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
spinner.setVisibility(View.GONE);
}
});
}
});
Upvotes: 2