If the textview is clicked the background changes to yellow and remains yellow until it is click again. Then it returns to its default background.
It's a matter of logic as you need to keep in your click listener the current click state.(blind coding):
textView.setOnClickClickListener(new View.OnClickListener() {
private boolean stateChanged;
public void onClick(View view) {
if(stateChanged) {
// reset background to default;
textView.setBackgroundDrawable(circleOffDrawable);
} else {
textView.setBackgroundDrawable(circleOnDrawable);
}
stateChanged = !stateChanged;
}
});
To improve the answer, you should keep stateChanged
flag in the activity and retain its value across activity recreations - if the user rotates the activity. (Store the flag in onSaveInstanceState
and restore in onCreate
if its parameter is not null.)