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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:27:08+00:00 2026-06-04T18:27:08+00:00

I have an issue with Spinners in a ListView . I have a ListView

  • 0

I have an issue with Spinners in a ListView. I have a ListView with a CheckBox, a label, and two Spinners. The Spinner are populated from SQLite and that is working fine. I am not using the ViewHolder method because so far when the ListView row is clicked the CheckBoxes are checked or unchecked and the change is immediately saved to the database. When the row is checked the Spinners are made visible but are not visible when the row is not checked.

So the issue that I haven’t managed to find a solution for is that I have no idea how to get the actual Spinner or even get the ListItem row that the clicked Spinner is on. The Activity extends ListActivity. Anyone know a way I can do this without using a ViewHolder or do I have to use a ViewHolder?

Here is the code that declares and populates the ListView:

mSsCursor = mDbHelper.fetchAllSsPlaylistSs(mPlId);
        startManagingCursor(mSsCursor);

        String[] from = new String[]{"pl_selected", BTDbAdapter.KEY_NAME, BTDbAdapter.KEY_NAME2};

        int[] to = new int[]{R.id.pl_selected, R.id.name, R.id.name2};

        mAllSs = new SimpleCursorAdapter(this, R.layout.pl_edit_ss_row, mSsCursor, from, to);
        mAllSs.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        //custom handling of setting the value
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if(columnIndex == 3) {
                    ViewGroup row = (ViewGroup)view.getParent().getParent();
                    mSId = cursor.getInt(0);
                    if (cursor.getInt(3) > 0) {
                        mCheckBox = (CheckBox) row.findViewById(R.id.pl_selected);
                        mCheckBox.setChecked(true);
                        mTSpin = (Spinner) row.findViewById(R.id.pl_t_spin);
                        mMSpin = (Spinner) row.findViewById(R.id.pl_m_spin);
                        mtvT = (TextView) row.findViewById(R.id.pl_t);
                        mtvM = (TextView) row.findViewById(R.id.pl_m);
                        mTSpin.setVisibility(View.VISIBLE);
                        mtvT.setVisibility(View.VISIBLE);
                        mMSpin.setVisibility(View.VISIBLE);
                        mtvM.setVisibility(View.VISIBLE);
                        //set the values in the t spinner
                        PopulateTSpinner(cursor.getInt(4));
                        //set the values in the m spinner
                        PopulateMSpinner(cursor.getInt(5));
                    }
                    else {
                        mCheckBox = (CheckBox) row.findViewById(R.id.pl_selected);
                        mCheckBox.setChecked(false);
                        mTSpin = (Spinner) row.findViewById(R.id.pl_t_spin);
                        mMSpin = (Spinner) row.findViewById(R.id.pl_m_spin);
                        mtvT = (TextView) row.findViewById(R.id.pl_t);
                        mtvM = (TextView) row.findViewById(R.id.pl_m);
                        mTSpin.setVisibility(View.GONE);
                        mtvT.setVisibility(View.GONE);
                        mMSpin.setVisibility(View.GONE);
                        mtvM.setVisibility(View.GONE);
                    }                   
                    return true;
            }
            return false;
        }
    });
    setListAdapter(mAllSs);

Thanks.

  • 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-04T18:27:09+00:00Added an answer on June 4, 2026 at 6:27 pm

    I don’t know if I understood your question: If your app flow is:

    show a list of data(CheckBox + TextView(Spinners hidden)) ->
    user clicks a row(the Spinners appear for that row with(individual) data) ->
    user selects something in those Spinners->
    save that selection in the database

    then I think you should go with a custom adapter and take care yourself of the row creation + data binding(I don’t see how you would set a listener for the Spinners). Below is a small example on how you might do this(although probably not a pretty way of doing it):

    public class CustomAdapter extends SimpleCursorAdapter {
    
            private LayoutInflater mInflater;
    
            public CustomAdapter(Context context, int layout, Cursor c,
                    String[] from, int[] to) {
                super(context, layout, c, from, to);
                mInflater = LayoutInflater.from(context);
            }
    
            @Override
            public void bindView(View view, Context context, Cursor cursor) {
                ViewHolder holder = (ViewHolder) view.getTag(); // the holder
                                                                // pattern
                // set the text for the TextView in your row
                holder.name
                        .setText(cursor.getString(cursor.getColumnIndex("name")));
                // status of the CheckBox from the database
                int status = cursor.getInt(cursor.getColumnIndex("pl_selected"));
                // set the CheckBox status
                holder.ckb.setChecked((status > 0) ? true : false);
                // get the id of this particular row, we'll use this later in the
                // Spinner's listeners
                long theId = cursor.getLong(cursor.getColumnIndex("_id"));
                // see if it is time to show the Spinners
                if (status > 0) {
                    // it is time to show the Spinners. Here you would do stuff
                    // like: setting up the Spinner's adapters + setting the
                    // listener
                    // I used a Spinner with entries set in the xml layout(so my
                    // selection result is a String)
                    holder.spin1.setVisibility(View.VISIBLE);
                    holder.spin2.setVisibility(View.VISIBLE);
                    // set theId as a tag so you know which Spinner was acted on
                    holder.spin1.setTag(new Long(theId));
                    holder.spin1
                            .setOnItemSelectedListener(new OnItemSelectedListener() {
    
                                @Override
                                public void onItemSelected(AdapterView<?> parent,
                                        View view, int position, long id) {
                                    Long realRowId = (Long) parent.getTag();
                                    // I don't know
                                    ContentValues cv = new ContentValues();
                                    // the column where I saved the spinner selected
                                    // item is called "saved_item"
                                    cv.put("saved_item", (String) parent
                                            .getItemAtPosition(position));
                                    // mDb is my SQLiteDatabase instance
                                    mDb.update("tbl", cv, "_id = ?",
                                            new String[] { String
                                                    .valueOf(realRowId) });
                                    // I don't know how you saved the data, the
                                    // above is just an example
                                }
    
                                @Override
                                public void onNothingSelected(AdapterView<?> parent) {
    
                                }
                            });
                    // also implement the second Spinner like the first one
                } else {
                    // required to prevent a recycled View from causing damage
                    holder.spin1.setVisibility(View.GONE);
                    holder.spin2.setVisibility(View.GONE);
                }
            }
    
            @Override
            public View newView(Context context, Cursor cursor, ViewGroup parent) {
                View v = mInflater.inflate(R.layout.adapters_listspinner_row,
                        parent, false);
                ViewHolder holder = new ViewHolder();
                holder.spin1 = (Spinner) v.findViewById(R.id.spinner1);
                holder.spin1.setFocusable(false);
                holder.spin2 = (Spinner) v.findViewById(R.id.spinner2);
                holder.spin2.setFocusable(false);
                holder.name = (TextView) v.findViewById(R.id.textView1);
                holder.ckb = (CheckBox) v.findViewById(R.id.checkBox1);
                holder.ckb.setFocusable(false);
                v.setTag(holder);
                return v;
            }
    
            class ViewHolder {
                Spinner spin1, spin2;
                TextView name;
                CheckBox ckb;
            }
    
        }
    

    Also, the required onListItemcClick method:

    @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
            // manage the CheckBox state
            CheckBox ckb = (CheckBox) v.findViewById(R.id.checkBox1);
            ckb.setChecked(!ckb.isChecked());
            ContentValues cv = new ContentValues();
            cv.put("pl_selected", ckb.isChecked() ? 1 : 0);
            mDb.update("tbl", cv, "_id = ?",
                    new String[] { String.valueOf(id) });
            // requery the database so the changes are seen by the adapter, this is horrible! 
            Cursor re = mDb.query("tbl", null, null, null, null, null, null);
            mAllSs.changeCursor(re);
        }
    

    As an advice, maybe you could modify the layout of your app and move the Spinners out of the ListView row.

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

Sidebar

Related Questions

I have a custom spinner that uses two custom views, one for the drop
Alright so i have been working on this Dynamic load of a spinner from
I have issue with Win2003 that Java Applet Closes IE for Users not Admins.
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I have an issue using Ajax upload with Spring 3 MVC. I understand that
I have an issue with processing data with PHP I retrieved from MySQL. This
I have issue wuth Firefox not displaying style text-decoration: line-through. I am using jqGrid
Much of my sql code is generated (from POD). Now i have issue where
I have a Spinner Control bind with data from Sqllite during the Page Load
i have done drag and drop using with jquery. here i have issue that

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.