Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:07:53+00:00 2026-06-04T09:07:53+00:00

I am trying to develop a spinner that can change the image of ImageView

  • 0

I am trying to develop a spinner that can change the image of ImageView according to the user selection. I have successfully developed the code like following But I would like to ask if it is possible to develop it in a manner that can easier for the purpose of management

My idea is to develop it into the format like that:

HK_map,R.drawable.map_101
UK_map,R.drawable.map_102
US_map,R.drawable.map_103

Shall I use hashmap or arraylist? May you help me some advice on how to improve it?Many Thanks in advance

My current Code[Updated]

package tool.mobile;

import java.util.ArrayList;
import java.util.List;   
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;

public class SpinnerActivity extends Activity implements OnItemSelectedListener{

private ImageView view2;
private Spinner spinner2;
private ArrayAdapter adapter2;
private List<HashMap<String, String>> items;
private Bitmap snoop;


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bible_help_1);

spinner2 = (Spinner) findViewById(R.id.spinner1);
view2 = (ImageView) findViewById(R.id.imageView1);

items = fillMaps();

SimpleAdapter adapter=new SimpleAdapter(this,items,R.layout.bible_help_spinner,
                new String[]{"name"},
                new int[]{R.id.title});


spinner2.setAdapter(adapter);

spinner2.setOnItemSelectedListener(this);

spinner2.setVisibility(View.VISIBLE);

}

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
    long arg3) {

HashMap map = (HashMap)items.get(arg2);
String Drawing_1= map.get("Drawing").toString();
int resID = getResources().getIdentifier(Drawing_1, "raw", "tool.mobile"); 
Bitmap snoop= BitmapFactory.decodeStream(getResources().openRawResource(resID));
imageshow.setImageBitmap(snoop);
imageshow.setTag(resID);
imageshow.setTag(resID);

}

public void onNothingSelected(AdapterView<?> arg0) {  
}

private List<HashMap<String, String>> fillMaps()
    {
        List<HashMap<String, String>> items = new ArrayList<HashMap<String,String>>();

        HashMap<String,String> i = new HashMap<String,String>();
            i.put("name","HK_map");
            i.put("Drawing", "map_101");
            items.add(i);

            i = new HashMap<String,String>();
            i.put("name","US_map");
            i.put("Drawing", "map_102");
            items.add(i);

return items;}



}

Current Problem

Currently, I am facing the problem of out-of-memory after viewing several images, may you give me some advice on how to solve the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:07:55+00:00Added an answer on June 4, 2026 at 9:07 am

    I think you should go with HashMap because it gives you key-value pair feature to accommodate both map name and its image resource value

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to develop an app for my ipad which i can
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I'm trying to develop an application question forum, where user can submit their answer
Im trying to develop my first ASP.NET MVC web app and have run into
im trying to develop an app for a win CE mobile device that downloads
I'm trying to develop a class that supports an asynchronus method invocation. This is
trying to develop web form using jquery. all i need is to have several
Im trying to develop a new FB App, however it seems they have changed
I am trying to develop a BlackBerry application that will show data from an
I'm trying to develop a JS function that creates a new row each time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.