-1

I am new to android and I am developing an application that has to change image according to data sent from another screen in android. How can this be achieved? Can someone please help me with this?

Gray
  • 115,027
  • 24
  • 293
  • 354
sneha
  • 39
  • 4
  • have you tried something. please post your code. – Nikhil Agrawal Apr 25 '13 at 21:16
  • do you want to pass data from one activity to another? if so, look at this question to see how to pass the data http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android – Elior Apr 25 '13 at 21:23

1 Answers1

1

You can send data from one activity to another by using extras.

On you first activity call something like this:

Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("SOME_ID", id_you_want_to_send);
startActivity(intent);

then in the other activity you can read this data by doing the following:

Bundle extras = getIntent().getExtras();
int id = -1;
if (extras != null) {
    id = extras.getInt("SOME_ID");
}

then you can set the image inside and if-else or a switch-case of your choosing and to change the image inside the image view you need the following code:

ImageView img = (ImageView)findById(your_image_id);
img.setImageResource(R.drawable.the_image_you_want_to_set);

where the image_you_want_to_set is inside the drawable folder of your project.

Hope that solves your problem

marimaf
  • 5,382
  • 3
  • 50
  • 68