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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:51:39+00:00 2026-05-31T22:51:39+00:00

I have Two spinner(Subject and Chapter),I crate two table(Chapter,subject). I add all subject name

  • 0

I have Two spinner(Subject and Chapter),I crate two table(Chapter,subject).
I add all subject name in subject spinner and i need to add all chapter name on the
basis of item selection in subject spinner. My question is that how to that,because my
code is not able to do this. Please give some hint or reference.
Here is my sample code.

in onCreate()

    addItemsOnSpinner1();
    addListenerOnSpinnerItemSelection();
    addItemsOnSpinner2();
    addListenerOnSpinner2ItemSelection();

using above calling function i call appropriate method.

private void addItemsOnSpinner1() {
    try
    {
        final MySQLiteHelper m=new MySQLiteHelper(getBaseContext());
        final List<ObjectiveWiseQuestion> LocWiseProfile= m.getAllSubject();

        for (final ObjectiveWiseQuestion cn : LocWiseProfile)
        {
            list.add(cn.getSubjectName());

        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            subSpinner.setAdapter(dataAdapter);

}

 private void addListenerOnSpinnerItemSelection()
{
    subSpinner.setOnItemSelectedListener(new mySpinnerListener());

}


private void addItemsOnChapter() 
{
    try
    {

        db=new MySQLiteHelper(getBaseContext());
        db.getWritableDatabase();
        //String name=owq.getSubjectName();
        int id=db.getSubjectId(name);
        owq.setSubjectId(id);
        long subId=owq.getSubjectId();
        final MySQLiteHelper m=new MySQLiteHelper(getBaseContext());
         final List<ObjectiveWiseQuestion> LocWiseProfile= m.getAllChapter(subId);

        for (final ObjectiveWiseQuestion cn : LocWiseProfile)
        {

            list.add(cn.getChapterName());
        }


        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            chapSpinner.setAdapter(dataAdapter);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

}
    private void addListenerOnSpinner2ItemSelection() 
{
    try
    {
        chapSpinner.setOnItemSelectedListener(new mySpinnerListener2());
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

}

Here is my Listener Class.

class mySpinnerListener2 implements Spinner.OnItemSelectedListener
{
    @Override
    public void onItemSelected(AdapterView parent, View v, int position,
            long id) 
    {
        Toast.makeText(parent.getContext(), "The chapter is  " +
                  parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
        owq.setChapterName(parent.getItemAtPosition(position).toString());

    }

    @Override
    public void onNothingSelected(AdapterView parent) 
    {
        // Do nothing.
    }

}
class mySpinnerListener implements Spinner.OnItemSelectedListener
{
    @Override
    public void onItemSelected(AdapterView parent, View v, int position,
            long id) 
    {
        Toast.makeText(parent.getContext(), "The subject is  " +
                  parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
        owq.setSubjectName(parent.getItemAtPosition(position).toString());
        name=parent.getItemAtPosition(position).toString();



    }

    @Override
    public void onNothingSelected(AdapterView parent) 
    {
        // Do nothing.
    }

}

When i am trying to compile it but it show null value. Give some help.
Thanks in Advance…….
Not find any good answer…..

MysqliteHelper.java

public List<ObjectiveWiseQuestion> getAllChapter(long subId)
    {
     List<ObjectiveWiseQuestion>LocwiseProfileList=new ArrayList<ObjectiveWiseQuestion>();
     String selectQuery=("select chapterName from chapter where s_id ='"+ subId +"'");
     SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst())
        {
            do {
                ObjectiveWiseQuestion owq= new ObjectiveWiseQuestion();
                owq.setChapterName(cursor.getString(2));
                LocwiseProfileList.add(owq);
              }
            while(cursor.moveToNext());
            db.close();
        }

        return LocwiseProfileList;
    }
  • 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-31T22:51:40+00:00Added an answer on May 31, 2026 at 10:51 pm

    Do the following change in your myspinnerlistener class.

       class mySpinnerListener implements Spinner.OnItemSelectedListener
        {
        Spinner chapSpinner;
            public mySpinnerListener(Spinner chapSpinner){
        this.chapSpinner = chapSpinner;
            }
            @Override
            public void onItemSelected(AdapterView parent, View v, int position,
                    long id) 
            {
                Toast.makeText(parent.getContext(), "The subject is  " +
                          parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
                owq.setSubjectName(parent.getItemAtPosition(position).toString());
                name=parent.getItemAtPosition(position).toString();
                // fetch the chaper names and set them on spinner
        chapSpinner.setAdapter(Here pass your adapter);
    
    
            }
    
            @Override
            public void onNothingSelected(AdapterView parent) 
            {
                // Do nothing.
            }
    
        }
    

    And this change also

     private void addListenerOnSpinnerItemSelection()
    {
        subSpinner.setOnItemSelectedListener(new mySpinnerListener(chapSpinner));
    
    }
    

    I think this will solve your problem.

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

Sidebar

Related Questions

I have two identical tables and need to copy rows from table to another.
I have a custom spinner that uses two custom views, one for the drop
I have two spinners in an activity, A and B. Each spinner uses an
I have two spinners that trigger the onItemSelected event. The question is How can
Have two bean definitions: file a.xml <bean id=A class=com.A> <property name=bClass ref=B/> </bean> file
I have two spinner in my system. Now I have to change the selected
i have two spinner one is for country and the second one is for
So, I have two spinners, let's call the first spinner Parent (account_type_spinner) and the
So my situation is this. I have two tables. A main table where data
i have a spinner an two buttons on my Android app, the spinner is

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.