0

what I actually need is when I click a radio button in the child view I want the text in that radio button to be set to the selected_child TextView in the header layout. I have tried many ways. But i cannot identify the parent view uniquely inside the getChildView method, Can any one help me with this ?

I have expandable list header layout like below.

<?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>

In my child view I generate radio buttons dynamically like below

@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;
}
DRayen
  • 87
  • 1
  • 12
  • i don't get correct idea from your code but may be you should do something like parantelistitem.get(groupPosition).settitle(childText) and notify the adapter – Raj Dec 15 '17 at 06:27
  • @Raj sorry I am new on Android. what do you mean by parentlistitem ? I am actually using an Expandable list view – DRayen Dec 15 '17 at 06:29
  • parantelistitem is just an example. It is your main arraylist which is you are passing in your adapter's constructor. You need to update value in your arraylist and needs to notify change in your adapter. – Raj Dec 15 '17 at 06:39
  • Actually what I need is this. There is an additional textView in my header layout `selected_child`. When I click a radio button in my child view I want the selected text to be displayed in the additional TextView. No changes in the array list. – DRayen Dec 15 '17 at 07:01
  • 1
    So as per my understanding header layout means parent view and radio view is child view. When you click on the radio button you want to change the text in header layout means parent item. But one thing you need understand that your view is already set now if you wants to render something like you want change header's text view. You need to use notifyDataSetChanged() which inform your adapter that some data is changed and new view needs to render. – Raj Dec 15 '17 at 07:07
  • @Raj thanks, mate. your comment helped me to solve the issue for me. – Taimur Hassan Jan 08 '19 at 17:02

0 Answers0