I want change imageButtons from another activity but that does not work This is my MainActivity:
boolean defaultValue = false;
SharedPreferences prefs = getSharedPreferences("YourAppNamePrefs", MODE_PRIVATE);
boolean shouldChangeButton = prefs.getBoolean("shouldChangeButton", defaultValue);
if(shouldChangeButton) {
ImageButton ib = (ImageButton) findViewById(R.id.imageButton10);
ib.setVisibility(View.VISIBLE);
}
boolean defaultValue1 = false;
SharedPreferences prefs1 = getSharedPreferences("YourAppNamePrefs1",MODE_PRIVATE);
boolean shouldChangeButton1 = prefs1.getBoolean("shouldChangeButton1",defaultValue1);
if (shouldChangeButton1) {
ImageButton ib1 = (ImageButton) findViewById(R.id.imageButton11);
ib1.setVisibility(View.VISIBLE);
}
This is anotheractivity:
public void onClick7 (View view) {
Intent myIntent = new Intent(view.getContext(), historiak.class);
SharedPreferences prefs1 = getSharedPreferences("YourAppNamePrefs1", MODE_PRIVATE);
prefs1.edit().putBoolean("shouldChangeButton1", true).apply();
startActivity(myIntent);
finish();
MediaPlayer mediaPlayer = MediaPlayer.create(historia20.this, R.raw.dobre);
mediaPlayer.start();
}
public void onClick8 (View view) {
Intent myIntent = new Intent(view.getContext(), zemk.class);
SharedPreferences prefs = getSharedPreferences("YourAppNamePrefs", MODE_PRIVATE);
prefs.edit().putBoolean("shouldChangeButton", true).apply();
startActivity(myIntent);
finish();
MediaPlayer mediaPlayer = MediaPlayer.create(zem20.this, R.raw.dobre);
mediaPlayer.start();
}
When i run this app that write: Unfrotunately app has stopped Please help me Thank
0 comments:
Post a Comment