0

I want to create ExpandableListView with custom group layout which has one RadioButton, one EditText and one Button. Design Like following: Design Like following

I created custom layout for group view

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp" >

<RadioButton
    android:id="@+id/rbGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<EditText
    android:id="@+id/etGroup"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@android:color/transparent"
    android:ems="10"
    android:focusable="false" />

<Button
    android:id="@+id/btnEditGroupName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/edit" />
</LinearLayout>

And I used this layout in adapter

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.item_groups, parent, false);
    }

    final int ind = groupPosition;

    CustomGroup group = (CustomGroup) getGroup(groupPosition);
    EditText etGroup = (EditText) convertView.findViewById(R.id.etGroup);
    etGroup.setText(group.getName());

    ((CheckedTextView) convertView).setChecked(isExpanded);

    RadioButton rbGroup = (RadioButton) convertView.findViewById(R.id.rbGroup);
    rbGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                selectedGroup = ind; 
            }
        }
    });

    return convertView;
}

But in this case ExpandableListView doesn't expands on click

Ulphat
  • 734
  • 1
  • 7
  • 26

1 Answers1

1

You can take a view instead of any button or radio button in row xml of parent and set view at run time

or you can replace view by example here

Community
  • 1
  • 1
Rax
  • 1,347
  • 3
  • 20
  • 27