Friday, March 9, 2012

Re: [android-developers] problem in radioGroup.getCheckedRadioButtonId()

Yes, this behavior is expected:

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/CompoundButton.java#L108

The mOnCheckedChangeListener is your (application-provided) listener.

The mOnCheckedChangeWidgetListener is installed by the radio group, and is what updates the currently checked radio button index.

The former is called before the latter.

-- Kostya

09.03.2012 10:55, Ray Tayek пишет:
        OnCheckedChangeListener onCheckedChangeListener=new OnCheckedChangeListener(){
                public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
                        RadioButton radioButton=(RadioButton)buttonView;
                        int a=radioButton.getId();
                        ViewParent viewParent=buttonView.getParent();
                        RadioGroup radioGroup=(RadioGroup)viewParent;
                        if(isChecked) {
                                button.setText(radioButton.getText());
                                int a2=radioGroup.getCheckedRadioButtonId();
                                if(a2!=a) {
                                        System.err.println("CompoundButton id="+a);
                                        System.err.println("radioGroup.getCheckedRadioButtonId()="+a2);
                                }
                        }
                }
        };

--  Kostya Vasilyev 

No comments:

Post a Comment