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

  • Home
  • SEARCH
  • 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 4381210
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:37:15+00:00 2026-05-21T12:37:15+00:00

In my app, I have a Spinner , that can be filled with two

  • 0

In my app, I have a Spinner, that can be filled with two Arrays of Strings, stored in my values/strings.xml resource. Depending on the state of two RadioButtons, the values from the correct Array is selected and my Spinner gets filled.

For each Array of Strings, I have an Array of Icons which have the same size. All of my icons start with an “A” and are followed by a number. I can’t change this, it’s stored like that in the database. I have an Array in Strings.xml with all the numbers I require to draw the icons. All the actual icons can be found in the drawable resource folder.

Now I want to show the corresponding item next to the String from the list which was selected by the Spinner. When an item gets selected, I just need to see the text.

I have searched the Internet for a good tutorial, but with what I have found I have not succeeded in doing this. I’m just beginning in Android programming so I think I need a little help. I hope that somebody can guide me in the right direction.

I put my String Array within actual Arrays, such as:

// Arrays with each function in text
arbeiderjobs = getResources().getStringArray(R.array.arbeiders);
bediendejobs = getResources().getStringArray(R.array.bediende);

// Arrays with each function ID
arbeiderjobsid = getResources().getIntArray(R.array.arbeidersid);
bediendejobsid = getResources().getIntArray(R.array.bediendeid);

When one of the RadioButtons gets selected, I use the following event handler code:

// RadioButton 'Arbeider': If a value gets chosen in this list, 
// the corresponding ID is put in the below variable 
RadioButton rbArbeider = (RadioButton) findViewById(R.id.rbArbeider);
rbArbeider.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
  {
    if (isChecked)
    {
      showSpinner(arbeiderjobs, R.id.cmbFuncties);
      s.setOnItemSelectedListener(new OnItemSelectedListener() 
      {
        public void onItemSelected(AdapterView<?> parentView, 
                                   View selectedItemView, int position, long id)
        {
          functie = arbeiderjobsid[position];
          statuut = 1;
          visible = false;  
        }
      });

      visible = true;
    }
  } // s.setOnItemSelectedListener

}); // rbArbeider.setOnCheckedChangeListener

This is my showSpinner method:

private void showSpinner(String [] jobs, int id)
{    
  MyCustomAdapter adapter = new MyCustomAdapter
  (
    FindJob.this, 
    R.layout.spinnerrow, 
    jobs
  );

  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

  for (int i = 0; i < jobs.length; i++)
  {
    adapter.add(jobs[i]);
  }

  Spinner s = (Spinner) findViewById(id);
  s.setClickable(true);
  s.setAdapter(adapter);
}

I’ve made a custom adapter based on this tutorial, but I’m kind of tangled in it… I need some help:

public class MyCustomAdapter extends ArrayAdapter<String>
{

  public MyCustomAdapter(Context context, int textViewResourceId, 
                         String[] objects) 
  {
    super(context, textViewResourceId, objects);
  }

  @Override
  public View getDropDownView(int position, View convertView, ViewGroup parent) 
  {
    return getCustomView(position, convertView, parent, 
                         arbeiderjobs, arbeiderjobsid);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) 
  {
    return getCustomView(position, convertView, parent, 
                         arbeiderjobs, arbeiderjobsid);
  }

  public View getCustomView(int position, View convertView, ViewGroup parent,                                                         
                            String jobs[], int jobsid[]) 
  {
    // return super.getView(position, convertView, parent);

    LayoutInflater inflater = getLayoutInflater();
    View row = inflater.inflate(R.layout.spinnerrow, parent, false);
    TextView label = (TextView) findViewById(R.id.functie);
    label.setText(jobs[position]);

    ImageView icon = (ImageView) row.findViewById(R.id.icon);

    String uri = "@drawable/a" + jobsid[position];
    int imageResource = getResources().getIdentifier
    (  
      uri, 
      null, 
      getPackageName()
    );
    icon.setImageResource(imageResource);

    if (visible)
    {
      icon.setVisibility(View.GONE);
    }

    return row;
  }

}

This is what I would want it to look like:

Result

  • 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-05-21T12:37:16+00:00Added an answer on May 21, 2026 at 12:37 pm

    You need to implement a custom Adapter and define a custom layout for the list items. Check this tutorial.

    UPDATE

    Try the following. I haven’t tested the code but I think it should work like that.

    public class MyCustomAdapter extends ArrayAdapter<String>{
    
        private String[] mIcons;
    
        public MyCustomAdapter(Context context, int textViewResourceId,
        String[] objects, String[] icons) {
            super(context, textViewResourceId, objects);
            mIcons = icons;
        }
    
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }
    
        public View getCustomView(int position, View convertView, ViewGroup parent) {
    
           LayoutInflater inflater=getLayoutInflater();
           View row=inflater.inflate(R.layout.spinnerrow, parent, false);
           TextView label=(TextView) findViewById(R.id.functie);
           label.setText(getItem(position);
    
           ImageView icon=(ImageView)row.findViewById(R.id.icon);
    
           String uri = "@drawable/a" + mIcons[position];
           int imageResource = getResources().getIdentifier(uri, null, getPackageName());
           icon.setImageResource(imageResource);
    
           return row;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one spinner in which few values are there from strings.xml and I
While developing my app I have come to realize that the majority of my
In my qt app I have this object, filled before setting up my QTreeWidget's
I have an application, which has a Spinner that I want populated with some
In my app I have a navigation menu that is constant between activities. To
In my app have a window splitted by a QSplitter, and I need to
On my rails app I have a list of items (like a task list)
For my Django app I have Events, Ratings, and Users. Ratings are related to
In my app I have 2 divs, one with a long list of products
I'm creating a WPF app and have a system tray icon with a context

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.