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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:13:04+00:00 2026-05-28T02:13:04+00:00

I am a newbie to Android programming. I want two radio buttons that when

  • 0

I am a newbie to Android programming.

I want two radio buttons that when clicked it will change the spinner array.

I know it sounds simple. I have it all working but I am not sure how to implement the onclickchange to make this happen. I have attached the code.

I am having an awful time trying to get my head around how to set this listener. Also, I have no errors, and spinner works, just can’t get it to change arrays.

Any guidance is greatly appreciated.
Cheers,

I attempted to create it with the listener, but it doesnt work, any advice is appreciated.

Xml

<RadioGroup
    android:id="@+id/radiogroup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RadioButton
        android:id="@+id/radiobutton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/radio1" />

    <RadioButton
        android:id="@+id/radiobutton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio2" />
</RadioGroup>

java

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.canprovselect);


    RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup1);

    int checkedRadioButton = radioGroup.getCheckedRadioButtonId();

    Spinner spinner = (Spinner) findViewById(R.id.spinner);     
    ArrayAdapter<CharSequence> adapter = null;

    String radioButtonSelected = "";
    switch (checkedRadioButton) {
    case R.id.radiobutton3 : radioButtonSelected = "radiobutton1";

    adapter = ArrayAdapter.createFromResource(
            this, R.array.prov_array, android.R.layout.simple_spinner_item);     
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new OnItemSelected(
            ));

    break;
    case R.id.radiobutton4 : radioButtonSelected = "radiobutton2";
    adapter = ArrayAdapter.createFromResource(             
            this, R.array.prov1_array, android.R.layout.simple_spinner_item);     
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new OnItemSelected(
            ));

    break;
    }

My attempt at a listener

public class CanProvselect extends Activity {

RadioButton myOption1, myOption2;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.canprovselect);
    myOption1 = (RadioButton)findViewById(R.id.radio_1); 
    myOption2 = (RadioButton)findViewById(R.id.radio_2); 
    myOption1.setOnClickListener(myOptionOnClickListener); 
    myOption2.setOnClickListener(myOptionOnClickListener); 

    OnClickListener myOptionOnClickListener = null;

    Spinner spinner = (Spinner) findViewById(R.id.spinner);     
    ArrayAdapter<CharSequence> adapter = null;


}

RadioButton.OnClickListener myOptionOnClickListener = 
        new RadioButton.OnClickListener() 
{

    @Override 
public void onClick(View v) { 
        // TODO Auto-generated method stub 
        //switch (checkedRadioButton) {     
        myOption1 : radioButtonSelected = "radio_1";      
        adapter = ArrayAdapter.createFromResource(             
                this, R.array.prov_array, android.R.layout.simple_spinner_item);          
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);          
        spinner.setAdapter(adapter);     
        spinner.setOnItemSelectedListener(new OnItemSelected(             
                ));

        myOption2 : radioButtonSelected = "radio_2";     
        adapter = ArrayAdapter.createFromResource(                          
                this, R.array.prov1_array, android.R.layout.simple_spinner_item);          
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);          
        spinner.setAdapter(adapter);     
        spinner.setOnItemSelectedListener(new OnItemSelected(             
        )); 
    }
}

}

  • 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-28T02:13:05+00:00Added an answer on May 28, 2026 at 2:13 am

    You need to set radioGroup.setOnClickListener(yourListenerClass). Here is an example.Radio button onclick event

    In that there is onClick method with Toast message, replace that with your listview population code.

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

Sidebar

Related Questions

I am a newbie to Android and Java and want to write a function
i'm newbie for android dev, now i want explore file handling in android, for
I am a complete Android programming newbie. I have completed some tutorial examples like
I'm a newbie Android developer. I would like to know if there exists a
I am a newbie to android development, and would like to know if it
I'm a completely newbie to android programming, having done some java for my computing
I know Java apps can be run in Android. But what I want to
This might sound stupid, but I'm seriously a newbie at Android programming. I have
I am a newbie to Android platform. I want to call a webservice from
I am newbie in android .i want to develop an application which has the

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.