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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:36:34+00:00 2026-05-15T13:36:34+00:00

I created two Spinners to display the data in my application. In my first

  • 0

I created two Spinners to display the data in my application. In my first Spinner, the first item of the list is always displayed directly, but in the second Spinner nothing is displayed, even if I click on an item on the drop down view. Can anybody explain this behaviour?

Here is the code of the initialisation of the two spinners:

projects = new Spinner(lexs);
projectAdapter = new ProjectAdapter();
projects.setAdapter(projectAdapter);
projects.setMinimumWidth(250);
projects.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
   updateSpinners(position);                    
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
   // do nothing    
}

});

projectsList = new Spinner(lexs);
projectsList.setMinimumWidth(250);
listAdapter = new ListAdapter();
projectsList.setAdapter(listAdapter);
projectsListLayer.addView(projectsList);

The Spinner projects is the first Spinner which works correctly. projectsList is the second Spinner which doesn’t work correctly. Here are the two implementations of the adapters:

private class ProjectAdapter implements SpinnerAdapter {

        @Override
        public View getDropDownView(int position, View arg1, ViewGroup arg2) {
            TextView text = new TextView(lexs);
            text.setText(allProjects.get(position).getName());
            return text;
        }

        @Override
        public int getCount() {
            return allProjects.size();
        }

        @Override
        public Object getItem(int position) {
            return allProjects.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public int getItemViewType(int arg0) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(int position, View arg1, ViewGroup arg2) {
            TextView text = new TextView(lexs);
            text.setText(allProjects.get(position).getName());
            return text;
        }

        @Override
        public int getViewTypeCount() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }

        @Override
        public boolean isEmpty() {
            if (allProjects.size() == 0) {
                return true;
            } else {
                return false;
            }
        }

        @Override
        public void registerDataSetObserver(DataSetObserver arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void unregisterDataSetObserver(DataSetObserver observer) {
            // TODO Auto-generated method stub

        }

    }

    private class ListAdapter implements SpinnerAdapter {

        @Override
        public View getDropDownView(int position, View view, ViewGroup parent) {
            TextView text = new TextView(lexs);
            text.setText(allLists.get(position).getName());
            return text;
        }

        @Override
        public int getCount() {
            return allLists.size();
        }

        @Override
        public Object getItem(int position) {
            return allLists.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public int getItemViewType(int position) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView text = new TextView(lexs);
            text.setText(allLists.get(position).getName());
            return text;
        }

        @Override
        public int getViewTypeCount() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public boolean hasStableIds() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isEmpty() {
            if (allLists.size() == 0) {
                return true;
            } else {
                return false;
            }
        }

        @Override
        public void registerDataSetObserver(DataSetObserver observer) {
            // TODO Auto-generated method stub
        }

        @Override
        public void unregisterDataSetObserver(DataSetObserver observer) {
            // TODO Auto-generated method stub
        }

    }

Here I attached a picture of the problem:

http://www.freeimagehosting.net/image.php?7684c157b8.png

  • 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-15T13:36:34+00:00Added an answer on May 15, 2026 at 1:36 pm

    The only thing I can suggest is to throw in a few log statements and check if allLists.size() > 0 before and after your updateSpinners call.

    Also, now that I think about it. You also need to notify the spinner that the data has changed by calling BaseAdapter#notifyDataSetChanged. Otherwise it won’t know that it has new data to display. So you should extend BaseAdapter and implement SpinnerAdapter. BaseAdapter will handle the implementation of registerDataSetObserver and unregisterDataSetObserver. You’ll probably also need to have your updateSpinners call into your ListAdapter‘s notifyDataSetChanged.

    Check out the ArrayAdapter source.

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

Sidebar

Related Questions

I have created an item swapper control consisting in two listboxes and some buttons
I created two tables: Publisher PK, PublisherId, int, not null, indentity +1 PublisherName, varchar(50),
I've created two functions to load expanded views of a month in the archive
I've recently created these two (unrelated) methods to replace lots of boiler-plate code in
Unfortunately, my question is not as simple as keeping track of two windows created
I created the following code to calculate the duration between two timestamps which can
A python script is running two parallel python processes ( created via os.fork() )
I've created a small python script to toggle between two files I'm using for
I've got two PostgreSQL databases that have been created using the same sql file.
I've created a user control (in vb.net code) that contains two dock panels, one

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.