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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:36:45+00:00 2026-05-24T06:36:45+00:00

I’ve created a custom adapter for my spinner because I wanted to have multiple

  • 0

I’ve created a custom adapter for my spinner because I wanted to have multiple rows. However, I would basically like to recreate androids spinner model with the radio button that gets selected when a spinner item is selected. Everything is working fine except I don’t understand how to check the radio button when a list item is selected.

My SimpleCursorAdapter Custom Adapter code:

    @Override
public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) {
    super.newDropDownView(context, cursor, parent);

    View view = View.inflate(context, R.layout.grain_spinner_row, null);
    int nameColumn = cursor.getColumnIndex("name");
    String getName = cursor.getString(nameColumn);
    TextView name = (TextView)view.findViewById(R.id.GrainSpinnerName);
    name.setText(getName);

    int loviColumn = cursor.getColumnIndex("lovibond");
    String getLovi = cursor.getString(loviColumn);
    TextView lovi = (TextView)view.findViewById(R.id.GrainSpinnerLovibond);
    lovi.setText(getLovi);

    int gravityColumn = cursor.getColumnIndex("gravity");
    String getGravity = cursor.getString(gravityColumn);
    TextView gravity = (TextView)view.findViewById(R.id.GrainSpinnerGravity);
    gravity.setText(getGravity);

    rb = (RadioButton)view.findViewById(R.id.GrainSpinnerRadio);

    return view;
}

public static void toggleRadio(){
    if(!(rb.isChecked())){
        rb.toggle();
    }
}

OnSelectedItemChanged code:

        @Override
    public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
        //Collects the id from the currently selected item so we can use that to reference the ingredient in the recipe database.
        //Because we are using a SimpleCursorAdapter to populate nameSpinner, we must use a cursor to request currentName.
        Cursor cc = (Cursor)(nameSpinner.getSelectedItem());
        currentName = cc.getString(cc.getColumnIndex("name"));
        String sql = "SELECT * FROM grain WHERE name = '" + currentName + "' AND origin = '" + currentOrigin + "'";
        Cursor data = database.rawQuery(sql, null);
        data.moveToFirst();

        int nameColumn = data.getColumnIndex("name");
        int loviColumn = data.getColumnIndex("lovibond");
        int gravityColumn = data.getColumnIndex("gravity");
        int originColumn = data.getColumnIndex("origin");

        String currentIngredientName = data.getString(nameColumn);
        String currentIngredientLovi = data.getString(loviColumn);
        String currentIngredientGravity = data.getString(gravityColumn);
        String currentIngredientOrigin = data.getString(originColumn);

        addIngredient = new String[4];
        addIngredient[0] = currentIngredientName;
        addIngredient[1] = currentIngredientLovi;
        addIngredient[2] = currentIngredientGravity;
        addIngredient[3] = currentIngredientOrigin;



GrainSpinnerAdapter.toggleRadio();
    }

LogCat is giving me a nullexpression error at:

GrainSpinnerAdapter.toggleRadio();

and

if(!(rb.isChecked())){
  • 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-24T06:36:47+00:00Added an answer on May 24, 2026 at 6:36 am

    If your question is as simple as it seems (merely changing the state of the radio button upon spinner selection) you can call the toggle() method on your radio button which will invert the radio button’s state. you can also declare your RadioButton and call an isChecked method.

    RadioButton myRadioButton = (RadioButton) findViewById(R.id.My_RadioButton);
    
    public void YourSpinnerItemMethod () {
        if ( !(myRadioButton.isChecked()) )
             myRadioButton.toggle();
    }
    

    EDIT:

    OnSelectedItemChange {
      YOUR_CODE;
      Class_Containing_Radio_Button.toggleButton();
    }
    
    Class_Containing_Radio_Button.class {
      RadioButton myButton;
    
      toggleButton() {
        myButton.toggle();
      }
    
      onCreate() {
        myButton = (RadioButton) findViewById(R........);
      }
    }
    

    then you can also have a method that reacts to the RadioButton’s check state using the isChecked() method. Good Luck!

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have a text area in my form which accepts all possible characters from

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.