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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:53:11+00:00 2026-06-13T07:53:11+00:00

I am using 3 spinners in Alertdialog. while i am using spinners without onitemselectedlistener

  • 0

I am using 3 spinners in Alertdialog. while i am using spinners without onitemselectedlistener it populates correctly and when i am using onItemSelectedListener its not populating the values, And i tried some other suggestions from stackoverflow Questions now its populated first time when i click some item All the values will gone

i posted my alertdialog code here

AlertDialog.Builder myDialog = new AlertDialog.Builder(CameraDemo.this);
    myDialog.setTitle("Save");
    TableRow.LayoutParams rowparams = new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

    LinearLayout layout1 = new LinearLayout(CameraDemo.this);
    layout1.setOrientation(LinearLayout.VERTICAL);
    Spinner spin = new Spinner(CameraDemo.this);
    Cursor cursor = placeData.queueAllDoc();
    startManagingCursor(cursor);
    SimpleCursorAdapter cu = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor, new String[]{SQLiteoperations.DOC_TYPE}, new int[]{android.R.id.text1});
    cu.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(cu);

    spin.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position,
                long id) {
            if(mSpinnerInitializedCount < mSpinnerCount){
                mSpinnerInitializedCount++;
                return;                         
            }
            Cursor incursor1 = (Cursor) parent.getItemAtPosition(position);
            int did = incursor1.getInt(incursor1.getColumnIndex(SQLiteoperations.DOC_ID));
            doc_id = did;
            System.out.println(did);
            incursor1.close();
        }
        public void onNothingSelected(AdapterView<?> arg0) {
        return;
        }
    });

    LayoutParams TxtLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    final EditText saveEdt = new EditText(CameraDemo.this);
    LayoutParams locationEdtLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    saveEdt.setLayoutParams(locationEdtLayoutParams);

    final TextView saveTxt = new TextView(CameraDemo.this);
    saveTxt.setLayoutParams(TxtLayoutParams);
    saveTxt.setText("Name");
    TextView groupTxt = new TextView(CameraDemo.this);
    groupTxt.setLayoutParams(TxtLayoutParams);
    groupTxt.setText("Group");
    TextView clientTxt = new TextView(CameraDemo.this);
    clientTxt.setLayoutParams(TxtLayoutParams);
    clientTxt.setText("Client");
    TextView docTxt = new TextView(CameraDemo.this);
    docTxt.setLayoutParams(TxtLayoutParams);
    docTxt.setText("Document Type");

    TableRow grouprow = new TableRow(CameraDemo.this);
    grouprow.setLayoutParams(rowparams);
    final TableRow clientrow = new TableRow(CameraDemo.this);
    clientrow.setLayoutParams(rowparams);
    final TableRow docrow = new TableRow(CameraDemo.this);
    docrow.setLayoutParams(rowparams);
    final TableRow namerow = new TableRow(CameraDemo.this);
    namerow.setLayoutParams(rowparams);



    Spinner spin2 = new Spinner(CameraDemo.this);
    Cursor cursor2 = placeData.queueAllGroup();
    startManagingCursor(cursor2);
    SimpleCursorAdapter cu2 = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor2, new String[]{SQLiteoperations.GROUP_NAME}, new int[]{android.R.id.text1});
    cu2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin2.setAdapter(cu2);

    spin2.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position,
                long id) {
            if(mSpinnerInitializedCount < mSpinnerCount){
                mSpinnerInitializedCount++;
                return;                         
            }
            Cursor incursor2 = (Cursor) parent.getItemAtPosition(position);
            int gid = incursor2.getInt(incursor2.getColumnIndex(SQLiteoperations.GROUP_ID));
            group_id = gid;
            System.out.println(gid);
            incursor2.close();
        }
        public void onNothingSelected(AdapterView<?> arg0) {
            return;
        }
    });

    Spinner spin3 = new Spinner(CameraDemo.this);
    Cursor cursor3 = placeData.queueAllClient(1);
    startManagingCursor(cursor3);
    SimpleCursorAdapter cu3 = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor3, new String[]{SQLiteoperations.CLIENT_NAME}, new int[]{android.R.id.text1});
    cu3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin3.setAdapter(cu3);

    spin3.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position,
                long id) {
            if(mSpinnerInitializedCount < mSpinnerCount){
                mSpinnerInitializedCount++;
                return;                         
            }
            Cursor incursor3 = (Cursor) parent.getItemAtPosition(position);
            int cid = incursor3.getInt(incursor3.getColumnIndex(SQLiteoperations.CLIENT_ID));
            client_id = cid;
            System.out.println(cid);
            incursor3.close();
        }
        public void onNothingSelected(AdapterView<?> arg0) {
            return;
        }
    });

    grouprow.addView(groupTxt);
    grouprow.addView(spin2);
    clientrow.addView(clientTxt);
    clientrow.addView(spin3);
    docrow.addView(docTxt);
    docrow.addView(spin);
    namerow.addView(saveTxt);
    namerow.addView(saveEdt);

    layout1.addView(grouprow);
    layout1.addView(clientrow);
    layout1.addView(docrow);
    layout1.addView(namerow);

    myDialog.setView(layout1);
    myDialog.show();  

pls help me to find the problem

  • 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-13T07:53:12+00:00Added an answer on June 13, 2026 at 7:53 am

    I dont think you should close the cursor which you get by calling

    parent.getItemAtPosition(position);
    

    You are not querying anything. It is already managed by Activity

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

Sidebar

Related Questions

I have a selection for some items using a spinner widget. At the moment
Im trying to make an app that converts distance/area/volume using spinners as a unit
UPDATED: Hi i'm using spinner within AlertDialog.Builder to show the list of options to
I created a custom AlertDialog to display a Spinner and some EditText elements. When
i am trying to select an item using Spinners. I have a JSON file
I've been using PhoneGap for a while mainly focused at iOS and using mostly
I have been successfully running an app under android 2.2 (api8) using spinners with
In my app I'm using a spinners to let the user select an item
I've been able to successfully link two spinners to a database using a SimpleCursorAdapter.
I'm creating some pages with PrimeFaces 2.2.1 using the Showcase source-code as support. I

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.