ShelbyZork
Lurker
Hi:
I'm working through the "Hello View" tutorial on the developer.android website, and am looking for a best practice on how to do something.
My layout has a Spinner and an ImageView. When I select something for the spinner, I want to change the image in the ImageView.
So, in the Activity onCreate, I establish the listener for a spinner with spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
Now, within the listener, I need to "get a handle" for the ImageView.
As a crude solution, I successfully tried to
1. Create a public attribute in the Activity with:
public static Test2Activity act;
2. In the Activity onCreate, set it as:
act = this;
3. In the listener did:
ImageView imageView = (ImageView) Test2Activity.act.findViewById(R.id.birdimage);
4. so I could then change image with:
imageView.setImageResource(R.drawable.harpy);
Seems there's a better way! Any suggestions? Thanks!
Brian
I'm working through the "Hello View" tutorial on the developer.android website, and am looking for a best practice on how to do something.
My layout has a Spinner and an ImageView. When I select something for the spinner, I want to change the image in the ImageView.
So, in the Activity onCreate, I establish the listener for a spinner with spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
Now, within the listener, I need to "get a handle" for the ImageView.
As a crude solution, I successfully tried to
1. Create a public attribute in the Activity with:
public static Test2Activity act;
2. In the Activity onCreate, set it as:
act = this;
3. In the listener did:
ImageView imageView = (ImageView) Test2Activity.act.findViewById(R.id.birdimage);
4. so I could then change image with:
imageView.setImageResource(R.drawable.harpy);
Seems there's a better way! Any suggestions? Thanks!
Brian