I have setup 2 activities - one and two .
For activity 1, I have a EditText
and a button. When user open the app, it will show Activity One(just like the screenshot) to prompt user to key in a number. For example, 1 or 2.
What I am trying to do is that: I want to display a ImageView
in activity 2 when user key in a number in EditText
follow by a click on the button in activity 1.
- If user key in 1, it will display
1.png
in activity 2 - If user key in 2, it will display
2.png
in activity 2 - If user key in 3, it will display
3.png
in activity 2 etc...
the image will get from drawable
folder.
Please refer to this screenshot
[![enter image description here][1]][1]
I can pass the integer value through Intent
from activity 1 to 2 but I can't do it for ImageView. so that means the if else loop i have already done just that the ImageView
cant display.
get_image.setBackgroundResource(R.drawable.1); // here i can only key in 01 ( it will get image from Drawable folder 1.png). i cant put int value into it.
Or i shouldn't use get_image.setBackgroundResource?? Anyone can help? I stuck here for 1 day...
thanks in advance!
please check screenshot -> http://i.stack.imgur.com/53vjy.jpg
you can pass resource value in extras. try this way.
and in your ActivityTwo.java
Happy Coding.
In activity 2's on create
then use switch case for values from intent then
You said that you can pass integer value from activity 1 to 2 so just use that to find your image.
I may missing somethings because i can't understand when you said that "but i cant do it for imageview".
EDIT: after your addtional code. So you must map your integer value with your resource file name. You could not put your integer value to get_image.setBackgroundResource(R.drawable.id). I think in your situation you should use an array just store id of resource you need
int[] drawableIds = {R.drawable.01, R.drawable.02}
in your Activity2 and then use like thisget_image.setBackgroundResource(drawableIds[yourIntegerValue-1])
(ofcourse you should take care array out of index when you use this method).Try below code for your solution,
For Activity One write below code to redirect on activity 2
Now In Activity 2 write below code in onCreate method
Try this way might helps you.
then your Activity2 use,
Finally,
public class Activity2 extends Activity { private ImageView img;