没有为 ExpandableListView 触发 setOnChildClickListener

setOnChildClickListener not being fired for ExpandableListView

大家好我在我的应用程序中有一个可扩展的列表视图,我在适配器中动态地在子视图中生成单选按钮。我对可扩展列表视图中的 setOnChildClickListener 有要求。但不幸的是,由于单选按钮,它没有被解雇。我已经尝试在动态生成的单选按钮中将 setFocusable/setclickable 设置为 false。当我这样做时, setOnChildClickListener 被解雇了。但我不能 select 个单独的单选按钮。所以 none 有所帮助。谁能帮我解决这个问题?请参考我的适配器class方法,

这是我的适配器方法

@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    LayoutInflater infalInflater = (LayoutInflater) this.context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = infalInflater.inflate(R.layout.expandable_child_radio_layout, null);


    RadioGroup radioGroup = (RadioGroup) convertView.findViewById(R.id.radio_group1);
    radioGroup.setFocusable(false);
    final RadioButton[] rb = new RadioButton[listDataChild.get(this.listOptionsHeader.get(groupPosition)).size()];
    radioGroup.setOrientation(RadioGroup.VERTICAL);
    for (int i = 0; i < listDataChild.get(this.listOptionsHeader.get(groupPosition)).size(); i++) {
        rb[i] = new RadioButton(context);
        rb[0].setChecked(true);
        final String childText = (String) getChild(groupPosition, i);
        rb[i].setText(childText);
        rb[i].setId(i + 100);
        rb[i].setTag("radio-child " + childText);
        fontUtils.changeFontOfRadioButtontoOpenSansRegular(rb[i]);
        rb[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.letter_small));
        radioGroup.addView(rb[i]);
        rb[i].setFocusable(false);
    }
    return convertView;
}

这是我的子布局XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="left"
    android:layoutDirection="ltr"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="20dp">

        <RadioGroup
            android:id="@+id/radio_group1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </RadioGroup>

    </LinearLayout>

</LinearLayout>

这是我在主activity class.

中使用的onClick方法
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {

            System.out.println("I am called");
            expandableListView.collapseGroup(groupPosition);
            return false;
        }
    });

将 return 语句作为真,而不是假,并确保在设置适配器后设置它!

编辑:

因为你不能 select rbuttons 但你的 OnClick 被触发让我们手动添加 selection 到点击的按钮

RadioGroup radioGroup = (RadioGroup) convertView.findViewById(R.id.radio_group1);
radioGroup.setFocusable(false);
final RadioButton[] rb = new RadioButton[listDataChild.get(this.listOptionsHeader.get(groupPosition)).size()];
radioGroup.setOrientation(RadioGroup.VERTICAL);
for (int i = 0; i < listDataChild.get(this.listOptionsHeader.get(groupPosition)).size(); i++) {
    rb[i] = new RadioButton(context);
   // rb[0].setChecked(true);
    final String childText = (String) getChild(groupPosition, i);
    rb[i].setText(childText);
    rb[i].setId(i + 100);
    rb[i].setTag("radio-child " + childText);
    fontUtils.changeFontOfRadioButtontoOpenSansRegular(rb[i]);
    rb[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.letter_small));
    radioGroup.addView(rb[i]);
    rb[i].setOnClickListener(new OnClickListener() {

      @Override
         public void onClick(View v) {
            radioGroup.check(rb[i].getId());
      //if you allow multiple checked btns then leave it like that or if you don't then you need to check if there are other buttons checked in radioGroup and then unckeck them also in this method   
      });
    rb[i].setFocusable(false);