Search code examples
androidandroid-listviewandroid-listfragmentandroid-radiogroupandroid-radiobutton

Get ListItem id/position while clicking on RadioButton in that ListItem.


I have 3 RadioButtons along with some texts in my ListItem using CursorAdapter. I need to get the view (ListItem) position when i click any of the RadioButton in that ListItem. Because , clicking on the RadioButton does not mean that i am Clicking on the ListItem.


Solution

  • In bindView or newView:

    RadioButton radioButton = (RadioButton) view.findViewById(R.id.radio_button_id);
    radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            Log.d(TAG, cursor.getPosition());
        }
    });
    

    Also make sure cursor declared as final in method parameters.