单击子项时,在“可扩展列表”的标题布局中更改文本

时间:2017-12-15 06:05:19

标签: android expandablelistview expandablelistadapter android-radiobutton

我真正需要的是当我单击子视图中的单选按钮时,我希望该单选按钮中的文本设置为标题布局中的selected_child TextView。我尝试了很多方法。但是我无法在getChildView方法中唯一地识别父视图,任何人都可以帮助我吗?

我有可扩展的列表标题布局,如下所示。

<?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="start"
    android:layoutDirection="ltr"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/lblListHeader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="5dp"
            android:paddingLeft="16dp"
            android:paddingTop="@dimen/activity_horizontal_margin"
            android:text="This is a text"
            android:textColor="@color/black_background"
            android:textSize="@dimen/letter_small" />

        <TextView
            android:id="@+id/selected_child"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/activity_horizontal_margin"
            android:paddingLeft="16dp"
            android:text="Test text"
            android:textSize="@dimen/letter_small" />

    </LinearLayout>

</LinearLayout>

在我的孩子视图中,我动态生成单选按钮,如下所示

@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

    LayoutInflater inflater = LayoutInflater.from(context);
    convertView = inflater.inflate(R.layout.expandable_child_radio_layout, parent, false);

    final RadioGroup radioGroup = (RadioGroup) convertView.findViewById(R.id.radio_group1);
    radioGroup.removeAllViews();
    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);
        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]);
        final int finalI = i;
        rb[i].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("implementation goes here");
            }
        });
    }
    return convertView;
}

0 个答案:

没有答案