I am currently building an App which is almost ready for release, but I got a problem I'am stuck with for quiet a while. My App contains a button that once clicke changes its color to either red or green which indicates which can change dynamically. I now wan't to save the state of my Button with sharedPreferences. But everything I try fails. I know this sounds rude but it would be very cool if you could show me how you would do it.
So thats my class with the data for my item is stored in
public class MyItem {
private String taskText;
public MyItem(String line1) {
taskText = line1;
}
public String getTaskText() {
return taskText;
}
}
And this is the OnClick Method I created which changes the color of my Button. I am trying to save clicks
mButton = itemView.findViewById(R.id.button3);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clicks++;
if (clicks % 2 == 0)
mButton.setBackgroundResource(R.drawable.button_green);
else
mButton.setBackgroundResource(R.drawable.button_red);
}
});