-2

I'm using the following code below for an application.

I want to get imageview i1 to appear on an other activity. How can I do this?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_question1);
    monwin = MediaPlayer.create(this,R.raw.mysound);
    monlose = MediaPlayer.create(this,R.raw.mywrong);
    bt1 = (RadioButton) findViewById(R.id.rd1);
    bt2 = (RadioButton) findViewById(R.id.rd2);
    i1 = (ImageView) findViewById(R.id.c1);

    bt1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (bt1.isChecked()){
                i1.setVisibility(View.INVISIBLE);
                monlose.start();
            }
       }
    }
}
Unheilig
  • 16,196
  • 193
  • 68
  • 98
  • Sir, cant you write i1.bringToFront(); – Sandeep Bhandari Mar 03 '16 at 09:48
  • 1
    You cant simply ask a blank question without actually mentioning your problem. what do u mean by "Other activity"? Explain your question lil bit more. Post your xml code that will be helpful. – Rafique Mohammed Mar 03 '16 at 09:49
  • I want to sya that for example in Intent 1 i have an imageView that cannot be visible or not depending of a selection of a specifi c radio button.And when i go to the secod activity the image must be visible in this second activity – Amidou Florian Touré Mar 03 '16 at 09:56

1 Answers1

0

You should have sent the image source to the new activity like this-

Intent intent = new Intent(activity2.this, activity1.class);
intent.putExtra("image_src", "your image source here");
startActivity(intent);

And receive this from next activity like this-

Intent intent = getIntent();
String easyPuzzle = intent.getExtras().getString("image_src");

More is here.

And then change the source of your image in that page's view (XML) like this way.

But using Fragments is more useful for this purpose.

This tutorial may help u-

http://code.tutsplus.com/tutorials/android-ui-workshop-build-an-interactive-quiz-app--mobile-14208

Community
  • 1
  • 1
Abrar Jahin
  • 13,970
  • 24
  • 112
  • 161