I have a MainActivity.xml, Where I have ExpandableListView, In The ExpandableListView I have List of groups, every group have some items, behind the items I have button, I need to create onclick event on the button, I need to click on the button, and then open a small popup window, I have created a xml file with the popup, how to create the onclick event, im trying it for 1 week, but nothing works. where I must create the onclick..
ActivityMain.xml - the is the ExpandableListView
<TextView android:id="@+id/Header" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorACD_gray" android:fontFamily="@font/sourcesanspro_bold" android:padding="10dp" android:text="@string/acd_keyconfig" android:textAlignment="viewStart" android:textColor="@color/white" android:textSize="20sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <LinearLayout android:id="@+id/line" android:layout_width="wrap_content" android:layout_height="5dp" android:layout_below="@id/Header" android:layout_alignLeft="@+id/Header" android:layout_alignRight="@+id/Header" android:background="@color/colorACD_orange" android:orientation="horizontal" /> <ExpandableListView android:id="@+id/lvExp" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/line" android:layout_alignParentBottom="false" android:divider="@color/colorACD_orange" android:dividerHeight="2dp" android:groupIndicator="@drawable/settings_selector" />
List_Item.xml - there is the button
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/lblListItem" android:layout_width="144dp" android:layout_height="42dp" android:layout_marginStart="0dp" android:layout_marginLeft="5dp" android:layout_marginTop="0dp" android:layout_marginEnd="0dp" android:layout_marginBottom="0dp" android:gravity="center" android:paddingLeft="25dp" android:background="@color/colorACD_white" android:textColor="@color/colorACD_black" android:textSize="18sp" android:fontFamily="@font/sourcesansproregular"/> <Button android:id="@+id/button1" android:layout_width="115dp" android:layout_height="45dp" android:layout_marginLeft="250dp" android:fontFamily="@faont/robotoregular" android:text="@string/edit" android:onClick="clickFunc"/> <LinearLayout android:id="@+id/line" android:layout_width="391dp" android:layout_height="10dp" android:orientation="horizontal" />
- ExpandableListAdapter.java
``` package com.example.test;
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
```