I have a test application that changes the image on the button. My test app should have 3 functions. 1. When you click on the image button, change the background image of the button on from image 0 to image 1. (I can do it) When you click on the save button, it should be recorded which image stands on the image button. (I can't do this) When you restart the application, when you click on the load button, the image should appear on the image button, which was saved using the save button
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnSave:
saveText();
break;
case R.id.btnLoad:
loadText();
break;
case R.id.cardButton:
cardButton.setImageResource(R.drawable.n01);
cardButton.setTag(R.drawable.n01);
Integer resource = (Integer)cardButton.getTag();
default:
break;
}
}
void saveText() {
sPref = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor ed = sPref.edit();
"some code"
ed.apply();
Toast.makeText(this, "Text saved", Toast.LENGTH_SHORT).show();
}
void loadText() {
sPref = getPreferences(MODE_PRIVATE);
"some code"
Toast.makeText(this, "Text loaded", Toast.LENGTH_SHORT).show();
}