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 7756397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:48:44+00:00 2026-06-01T12:48:44+00:00

I would like to display two values in an drop down view of my

  • 0

I would like to display two values in an drop down view of my spinner.

Currently, it only has a city name, but I would also like to add a small distance field to it.

    MyCity<MyCityDistance> dataAdapter;  

    dataAdapter = new MyCity(this, R.layout.mycityrow, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

I have all the code for custom data adapter, exapanding my view and holder etc.

However, the item which gets show doesn’t display both the city and its distance from my current location.

It only shows what is overridden in toString() method of MyCityDistance class.

I even tried setting

dataAdapter.setDropDownViewResource(R.layout.mycityrow);

but, no success. It throws an error.

04-02 11:05:22.600: E/AndroidRuntime(367): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
04-02 11:05:22.600: E/AndroidRuntime(367):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
04-02 11:05:22.600: E/AndroidRuntime(367):  at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:376)
04-02 11:05:22.600: E/AndroidRuntime(367):  at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:332)

What is a good example of creating your own custom setDropDownViewResource()?

Even if I comment out the setDropDownViewResource() line, I get the same error.

Note: The only effect mycityrow current is that the first element of Spinner is show as per the layout of mycityrow. However, when I click open the drop down, that layout is lost. I want the same layout during drop down selection too.

  • 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-01T12:48:46+00:00Added an answer on June 1, 2026 at 12:48 pm

    Note the below example uses the inbuilt android.R.layout.simple_list_item_2, Unfortunately the text color will probably be the same as the background. You can simply solve this by creating your own custom view and use it in the adapter instead.

    Let me know if i should explain any part of it.

    public class MainActivity extends Activity {
    
        class City {
            public City(String city, int d) {
                this.city = city;
                this.distance = String.valueOf(d);
            }
    
            String city;
            String distance;
        }
    
        class CityAdapter extends ArrayAdapter<City> {
    
            public CityAdapter(Context context, List<City> objects) {
                super(context, android.R.layout.simple_list_item_2, objects);
            }
    
            @Override //don't override if you don't want the default spinner to be a two line view
            public View getView(int position, View convertView, ViewGroup parent) {
                return initView(position, convertView);
            }
    
            @Override
            public View getDropDownView(int position, View convertView,
                                        ViewGroup parent) {
                return initView(position, convertView);
            }
    
            private View initView(int position, View convertView) {
                if(convertView == null)
                    convertView = View.inflate(getContext(),
                                               android.R.layout.simple_list_item_2,
                                               null);
                TextView tvText1 = (TextView)convertView.findViewById(android.R.id.text1);
                TextView tvText2 = (TextView)convertView.findViewById(android.R.id.text2);
                tvText1.setText(getItem(position).city);
                tvText2.setText(getItem(position).distance);
                return convertView;
            }
        }
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Spinner spinner = (Spinner)findViewById(R.id.spinner1);
            List<City> list = new ArrayList<MainActivity.City>();
            for(int i = 0; i < 10; i++)
                list.add(new City(String.format("City %d", i + 1), (i + 1) * 1000));
            spinner.setAdapter(new CityAdapter(this, list));
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two collection_select drop down menus that are currently set up like so:
I would like to display the image of two real valued analytic functions f,g
I would like to display an image composed of two images. I want image
I would like to display only posts that are members of BOTH category 33,
I would like to display the first and last name of the authenticated user.
I would like to display other we pages in my mobile webapp, but some
I would like to validate some objects. The validation has two parts: validation whether
I have two tables that I would like to display as a single result,
I have two arrays of data that I would like to display in an
I would like to display a gallery of photos and how many times each

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.