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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:41:11+00:00 2026-06-01T18:41:11+00:00

I am developing an app in which I need a ListView whose rows have

  • 0

I am developing an app in which I need a ListView whose rows have a TextView, 2 CheckBox and a Spinner.

However, I am experiencing issues with onItemSelected() of the Spinner, as it gets called each time it is displayed for each row. In this method I am updating database records with the selected option, but as Android calls it automatically, every time the items get reset because Android calls it with position 0 and this is the value updated in the database.

I have read a lot of links about the issue with onItemSelected() and some hacks, but all of them are to use without a ListView. Any points here?

I have tried to track in a List which positions are actually displayed to make it work but it does not. I think it is because of the recycling in Android that causes the troubleshooting method get called for Spinners already shown!

So the point is: How can I differenciate a real call to onItemSelected() because of a user selection from the Android call when displaying the Spinner?

Here is the code of my adapter that extends SimpleCursorAdapter.

Thank you so much in advance.

public ParticipationAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
    super(context, layout, c, from, to);
    mActivity = (Activity)context;
    ParticipationComment.ParticipationCommentManager commentManager = new ParticipationComment.ParticipationCommentManager(mActivity);
    mParticipationCommentsCursor = commentManager.get();
    mActivity.startManagingCursor(mParticipationCommentsCursor);
    commentManager.detach();
    mPositionsOfCursorIds = getPositionsOfCursorIds(mParticipationCommentsCursor);
    mSpinnerPositionsDisplayed = new ArrayList<Integer>();
}

@Override
public View getView(final int participationPosition, View convertView, ViewGroup parent) {
    final Cursor participationsCursor = getCursor();
    mActivity.startManagingCursor(participationsCursor);
    participationsCursor.moveToPosition(participationPosition);
    View participationRow;
    if (convertView == null) {
        participationRow = LayoutInflater.from(mActivity).inflate(R.layout.participation_row_student, null);
    } else {
        mSpinnerPositionsDisplayed.remove((Integer)convertView.getTag());
        participationRow = convertView;
    }
    participationRow.setTag(participationPosition);
    Spinner commentSpinner = (Spinner)participationRow.findViewById(R.id.participation_comment_id_spinner);
    SimpleCursorAdapter commentSpinnerAdapter = new SimpleCursorAdapter(
            mActivity,
            android.R.layout.simple_spinner_item,
            mParticipationCommentsCursor,
            new String[] {DatabaseManager.NAME},
            new int[] {android.R.id.text1}
    );
    commentSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    commentSpinner.setAdapter(commentSpinnerAdapter);
    long participationCommentId = participationsCursor.getLong(participationsCursor.getColumnIndex(DatabaseManager.PARTICIPATION_COMMENT_ID));
    if (participationCommentId != 0) {
        commentSpinner.setSelection(mPositionsOfCursorIds.get(participationCommentId));
    }
    commentSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            participationsCursor.moveToPosition(participationPosition);
            if (!mSpinnerPositionsDisplayed.contains(participationPosition)) {
                // Android calls this method the first time a Spinner is displayed,
                // to differentiate from a real user click we check if the current Spinner's position
                // in the ListView is being shown
                mSpinnerPositionsDisplayed.add(participationPosition);
            } else {
                ParticipationComment participationComment = new ParticipationComment((Cursor)parent.getItemAtPosition(position));
                Participation.ParticipationManager participationManager = new Participation.ParticipationManager(mActivity);
                Participation participation = new Participation(participationsCursor);
                participation.setConnectionProfileParticipationCommentId(participationComment.getConnectionProfileId());
                participation.setParticipationCommentId(participationComment.getIdOpenErp());
                participation.setChanged(true);
                participationManager.update(participation);
                participationManager.detach();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // Not used
        }
    });
    TextView studentName = (TextView)participationRow.findViewById(R.id.participation_student_name);
    studentName.setText(participationsCursor.getString(participationsCursor.getColumnIndex(DatabaseManager.NAME)));
    CheckBox expectedPresent = (CheckBox)participationRow.findViewById(R.id.participation_expected_present_value);
    expectedPresent.setChecked(participationsCursor.getInt(participationsCursor.getColumnIndex(DatabaseManager.EXPECTED_PRESENT)) == 1);
    CheckBox present = (CheckBox)participationRow.findViewById(R.id.participation_present_value);
    present.setChecked(participationsCursor.getInt(participationsCursor.getColumnIndex(DatabaseManager.PRESENT)) == 1);
    return participationRow;
}
  • 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-01T18:41:12+00:00Added an answer on June 1, 2026 at 6:41 pm

    A better way is to use a AlertDialog Variant.. like this.. and create a button which initially has the first selection as its Text and its changed based on the AlertDialog choice..

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

Sidebar

Related Questions

I am developing an app which listens to incoming sms. I have added the
I have been developing an iPhone app which queries a server that relays data
We're developing an app (using Grails Spring Security (formerly Acegi)) in which we'll have
I am developing an android app in which i need to display images after
Im developing a app which has a user sign-up activity, there I need to
I am developing a app for a movie in which I need to fetch
I'm developing an app in which I need to do an action when the
I am developing an app which supposed to work on devices that have OS
I'm developing an app which will have a central database users can add entries
I am developing an app which uses gps. i need a high accuracy so

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.