0

Using a radiogroup to display a number of options on the UI. Currently using OnCheckedChangeListener() to detect an event on the radiogroup. The problem is OnCheckedChangeListener() only fires when a radiobutton other than the currently active radiobutton is selected.

I also want to trigger an event when the currently active radiobutton is selected.

I've tried onClick() on the radiogroup and radiobutton but no success...

Tips? Ideas? Workaround?

Strokes
  • 157
  • 7
  • 23
  • Possible duplicate: http://stackoverflow.com/questions/9748070/radio-group-onclick-event-not-firing-how-do-i-tell-which-is-selected – Thomas Bouron Apr 07 '14 at 10:34
  • He wants to get notified if already selected Item is clicked... Definitely not a duplicate of what you pointed out. – Faisal Ali Apr 07 '14 at 10:37
  • 1
    @Strokes you need to do some research before posting any thing... http://stackoverflow.com/questions/10440386/radiobutton-click-reclick – Faisal Ali Apr 07 '14 at 10:43
  • @FaisalAli Setting the onClickListener on each of the radiobuttons worked! Thanks very much. I did search the threads prior to posting here but didnt come across your suggested thread – Strokes Apr 07 '14 at 11:43

1 Answers1

0

You can try this as described in this

RadioGroup radioGroup;
RadioButton radioButton1;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    radioGroup = (RadioGroup) findViewById(R.id.rg);
    radioButton1 = (RadioButton) findViewById(R.id.r1);

    OnClickListener radioClickListener = new OnClickListener()
    {
        public void onClick(View v)
        {
            radioButtonClicked(radioButton1); // Or your selected Radiobutton
        }
    };

    OnCheckedChangeListener radioCheckChangeListener = new OnCheckedChangeListener()
    {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {
            radioButtonClicked(buttonView); // Your function to handle radioButton click
        }
    };

    radioButton1.setOnCheckedChangeListener(radioCheckChangeListener);
    radioButton1.setOnClickListener(radioClickListener);
} 
Community
  • 1
  • 1
Faisal Ali
  • 1,135
  • 10
  • 17