When I click on the Change Button button in the Button MainActivity.class
This is the activity with onClick button :
Public Zero onClick8 (View View) {// Change the image here onClick Intent myIntent = new intent (view.getContext (), MainActivity.class); StartActivity (myIntent); End(); Media Player Mediaplayer = Media PlayerCredit (zem13.this, R.raw.melody); MediaPlayer.start (); }
This is the code with codeButton in MainActivity:
If I understand well, you can change the image resource in the main resource You should give some indicators and set it in (CREATE) Try changing your code in this way:
public void onClick8 (see footage) {// Change on here imagebutton for onClick Intent myIntent = new Intent (view.getContext), MainActivity Class ); MyIntent.putExtra ("Change Button", true); StartActivity (myIntent); End(); Media Player Mediaplayer = Media PlayerCredit (zem13.this, R.raw.melody); MediaPlayer.start (); }
and then in the main activity:
@ override protected zero creation (bundle saved instanestate) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_main); Boolean default = false; // GetIentent () GetBeoleanExtra ("Change Button", Default Value) if you need it (); {ImageButton ib = (ImageButton) findViewById (R.id.imagebutton); Ib.setImageResource (R.drawable.img); }}
Or if you want a permanent change, then it should be kept instead of passing it intently:
public zero onClick8 (see view) { // Code from the onClick Intent myIntent = new Intent (view.getContext (), MainActivity.class) for the Change Image button here; Shared presentation prefs = getSharedPreferences ("YourAppNamePrefs", MODE_PRIVATE); Prefs.edit (). PutBoolean ("Change Button", true) .apply (); StartActivity (myIntent); End(); Media Player Mediaplayer = Media PlayerCredit (zem13.this, R.raw.melody); MediaPlayer.start (); }
and
@ override protected form to zero (bundle saved instainstate) {super.Nought (savedinstenstate); SetContentView (R.layout.activity_main); Boolean default = false; // Or you really need to share prefs = getSharedPreferences ("YourAppNamePrefs", MODE_PRIVATE); Boolean should changeBootun = prefs.getBoolean ("Replace Button", defaultVolicies); If (ChangeButton) (ImageButton ib = (ImageButton) findViewById (R.id.imagebutton); ib.setImageResource (R.drawable.img);}}
No comments:
Post a Comment