How to give each node unique name - java

I want to display a tree having the individual name of its parent, second node, and its child nodes. I've coded by using Google help. This code display tree has all second and child nodes with the same names. How can I give an unique name to each node of a tree?
My Java code is:
package com.example.tree;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
public class MainActivity extends Activity {
ExpandableListView explvlist;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
explvlist = (ExpandableListView)findViewById(R.id.ParentLevel);
explvlist.setAdapter(new ParentLevel());
}
public class ParentLevel extends BaseExpandableListAdapter
{
#Override
public Object getChild(int arg0, int arg1)
{
return arg1;
}
#Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
CustExpListview SecondLevelexplv = new CustExpListview(MainActivity.this);
SecondLevelexplv.setAdapter(new SecondLevelAdapter());
SecondLevelexplv.setGroupIndicator(null);
return SecondLevelexplv;
}
#Override
public int getChildrenCount(int groupPosition)
{
return 4;
}
#Override
public Object getGroup(int groupPosition)
{
return groupPosition;
}
#Override
public int getGroupCount()
{
return 1;
}
#Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
TextView tv = new TextView(MainActivity.this);
tv.setText("Unit Testing");
tv.setBackgroundColor(Color.BLUE);
tv.setPadding(10, 7, 7, 7);
return tv;
}
#Override
public boolean hasStableIds()
{
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return true;
}
}
public class CustExpListview extends ExpandableListView
{
int intGroupPosition, intChildPosition, intGroupid;
public CustExpListview(Context context)
{
super(context);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public class SecondLevelAdapter extends BaseExpandableListAdapter
{
#Override
public Object getChild(int groupPosition, int childPosition)
{
return childPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
TextView tv = new TextView(MainActivity.this);
tv.setText("Campaign Page should not be null");
tv.setPadding(15, 5, 5, 5);
tv.setBackgroundColor(Color.RED);
tv.setLayoutParams(new ListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return tv;
}
#Override
public int getChildrenCount(int groupPosition)
{
return 2;
}
#Override
public Object getGroup(int groupPosition)
{
return groupPosition;
}
#Override
public int getGroupCount()
{
return 1;
}
#Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
TextView tv = new TextView(MainActivity.this);
tv.setText("Get Campaign");
tv.setPadding(12, 7, 7, 7);
tv.setBackgroundColor(Color.CYAN);
return tv;
}
#Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
}
I want each second and child nodes of tree to have an unique name and different colors.

Means you want to see the tree of data depending on the parent name.? So you used expandable list view.? right..?
Use these code..
main.xml having
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardCodedText" >
<ExpandableListView
android:id="#+id/expandableListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dip"
android:groupIndicator="#null"
android:scrollbars="none" >
</ExpandableListView>
</RelativeLayout>
And create the one ExpandListGroup.java file and add these code
public class ExpandListGroup {
private String Name;
private ArrayList<ExpandListChild> Items;
public ExpandListGroup(String name, ArrayList<ExpandListChild> items) {
super();
Name = name;
Items = items;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public ArrayList<ExpandListChild> getItems() {
return Items;
}
public void setItems(ArrayList<ExpandListChild> items) {
Items = items;
}
}
Add the another one ExpandListChild.java file for child
public class ExpandListChild {
private String Name;
private String Tag;
public ExpandListChild(String name, String tag) {
super();
Name = name;
Tag = tag;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getTag() {
return Tag;
}
public void setTag(String tag) {
Tag = tag;
}
}
And add these code in your MainActivity.java
public class ConfigureMyOrderItem extends MainActivity {
private ArrayList<ExpandableConfigureGroup> group_list;
private ArrayList<ExpandableConfigureChild> child_list;
ExpandableListView mExpandableListView;
ConfigureMyOrderAdapter adapter;
Button btn_confirm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_configure_my_order_item);
initView();
}
public void initView() {
mExpandableListView = (ExpandableListView) findViewById(R.id.expandableListViewConfigure);
btn_confirm = (Button) findViewById(R.id.btn_Confirm_order);
btn_confirm.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(ConfigureMyOrderItem.this,
MyOrderActivity.class);
startActivity(intent);
}
});
group_list = SetStandardGroups();
adapter = new ConfigureMyOrderAdapter(ConfigureMyOrderItem.this,
mExpandableListView, group_list);
mExpandableListView.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater()
.inflate(R.menu.activity_configure_my_order_item, menu);
return true;
}
public ArrayList<ExpandableConfigureGroup> SetStandardGroups() {
group_list = new ArrayList<ExpandableConfigureGroup>();
child_list = new ArrayList<ExpandableConfigureChild>();
group_list.add(new ExpandableConfigureGroup("Group", child_list));
child_list.add(new ExpandableConfigureChild("Child1"));
child_list.add(new ExpandableConfigureChild("Child2"));
child_list.add(new ExpandableConfigureChild("Child3"));
child_list.add(new ExpandableConfigureChild("Child4"));
child_list = new ArrayList<ExpandableConfigureChild>();
group_list.add(new ExpandableConfigureGroup("Category",
child_list));
child_list.add(new ExpandableConfigureChild("Item1"));
child_list.add(new ExpandableConfigureChild("Item2"));
child_list.add(new ExpandableConfigureChild("Item3"));
child_list.add(new ExpandableConfigureChild("Item4"));
}
public void HomeButton(View v) {
startActivity(new Intent(v.getContext(), MainActivity.class));
}
#Override
public void onClickQuickView(View v) {
// TODO Auto-generated method stub
super.onClickQuickView(v);
}
#Override
public void onClickQuickViewStatus(View v) {
// TODO Auto-generated method stub
super.onClickQuickViewStatus(v);
}
}
Also create the ConfigureMyOrderAdapter.java file
public class ConfigureMyOrderAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<ExpandableConfigureGroup> groups;
private ExpandableListView mExpandableListView;
private int[] groupStatus;
public ConfigureMyOrderAdapter(Context context,
ExpandableListView mExpandableListView,
ArrayList<ExpandableConfigureGroup> groups) {
this.context = context;
this.groups = groups;
this.mExpandableListView = mExpandableListView;
groupStatus = new int[groups.size()];
setListEvent();
}
private void setListEvent() {
mExpandableListView
.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 1;
}
});
mExpandableListView
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 0;
}
});
}
public void addItem(ExpandableConfigureChild item,
ExpandableConfigureGroup group) {
if (!groups.contains(group)) {
groups.add(group);
}
int index = groups.indexOf(group);
ArrayList<ExpandableConfigureChild> ch = groups.get(index).getItems();
ch.add(item);
groups.get(index).setItems(ch);
}
public Object getChild(int groupPosition, int childPosition) {
ArrayList<ExpandableConfigureChild> chList = groups.get(groupPosition)
.getItems();
return chList.get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean arg2, View view, ViewGroup arg4) {
ExpandableConfigureChild child = (ExpandableConfigureChild) getChild(
groupPosition, childPosition);
if (view == null) {
#SuppressWarnings("static-access")
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(
R.layout.configure_list_raw_group_item, null);
}
TextView tv_price = (TextView) view.findViewById(R.id.item_price);
tv_price.setText(child.getTag().toString());
tv_price.setTag(child.getTag());
return view;
}
#Override
public int getChildrenCount(int groupPosition) {
ArrayList<ExpandableConfigureChild> chList = groups.get(groupPosition)
.getItems();
return chList.size();
}
#Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
#Override
public int getGroupCount() {
return groups.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#SuppressWarnings("static-access")
#Override
public View getGroupView(int groupPosition, boolean arg1, View view,
ViewGroup arg3) {
ExpandableConfigureGroup group = (ExpandableConfigureGroup) getGroup(groupPosition);
if (view == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.configure_list_raw_group, null);
}
TextView tv = (TextView) view.findViewById(R.id.txtRestaurantMenuName);
tv.setText(group.getName());
ImageView img = (ImageView) view.findViewById(R.id.img_rightarrow);
if (groupStatus[groupPosition] == 0) {
img.setImageResource(R.drawable.navigation_next);
} else {
img.setImageResource(R.drawable.navigation_expandable);
}
return view;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}
and also create the two xml for the custom configure_list_raw_group.xml layout. so it is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="45dip"
android:orientation="horizontal"
android:weightSum="100"
tools:ignore="HardCodedText" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="45dip"
android:layout_marginLeft="4dip"
android:layout_weight="88"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/txtRestaurantMenuName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RestaurantMenu Name"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:id="#+id/img_rightarrow"
android:layout_width="0dip"
android:layout_height="45dip"
android:layout_gravity="center_vertical"
android:layout_weight="7"
android:contentDescription="#string/hello_world"
android:src="#drawable/navigation_next_item" />
</LinearLayout>
and second for the child of group configure_list_raw_group_item.xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/groupItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal"
android:weightSum="100"
tools:ignore="HardCodedText" >
<TextView
android:id="#+id/item_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="75"
android:text="sample"
android:textSize="12sp" />
</LinearLayout>

Related

I want to make use of expandlelistView to display products and the sub products

I want to make use of expandlelistView to display products and the sub products, which is the childHolder, in the childHolder, it contains a textView and an Edittext which holds the value for the product count for each sub product, the problem here is this.
When I input the values in the edittext, upon collapsing the group, the data is lost in the edittext.
The values get duplicated in the other group edittext.
3.How to save the data for later use in the Application.
The code below.
The activity layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.activities.ShelfCheckActivity">
<ExpandableListView
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:dividerHeight="0dp"
android:groupIndicator="#null"
android:descendantFocusability="beforeDescendants"/>
</RelativeLayout>
The adapter class
public class ShelfCheckAdapter extends BaseExpandableListAdapter {
ArrayList<ListItemModel> groupItem;
GroupViewHolder groupViewHolder;
ChildViewHolder childViewHolder;
Context context;
public LayoutInflater layoutInflater;
public ShelfCheckAdapter(ArrayList<ListItemModel> groupItem, Context
context) {
this.groupItem = groupItem;
this.context = context;
}
public void setInflater(LayoutInflater inflater)
{
this.layoutInflater = inflater;
}
#Override
public int getGroupCount() {
return groupItem.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return groupItem.get(groupPosition).getArrayList().size();
}
#Override
public Object getGroup(int groupPosition) {
return groupItem.get(groupPosition);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return groupItem.get(groupPosition).getArrayList().get(childPosition);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View
convertView, ViewGroup parent) {
if(convertView == null)
{
groupViewHolder = new GroupViewHolder();
convertView = layoutInflater.inflate(R.layout.list_row_group,null);
groupViewHolder.groupTitle = (TextView)
convertView.findViewById(R.id.textViewGroup);
convertView.setTag(groupViewHolder);
}
else{
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
groupViewHolder.groupTitle.setText(groupItem.get(groupPosition).getTitle());
return convertView;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean
isLastChild, View convertView, ViewGroup parent) {
if(convertView == null)
{
childViewHolder = new ChildViewHolder();
convertView =
LayoutInflater.from(context).inflate(R.layout.list_row_child,null);
childViewHolder.childTitle =
convertView.findViewById(R.id.textViewChild);
childViewHolder.et = convertView.findViewById(R.id.productCount);
convertView.setTag(childViewHolder);
}
else{
childViewHolder = (ChildViewHolder) convertView.getTag();
}
childViewHolder.childTitle.setText(groupItem.get(groupPosition)
.getChildTitles().get(childPosition));
if (!groupItem.get(groupPosition).getArrayList()
.get(childPosition).getValue().equals(""))
childViewHolder.et.setText(groupItem.get(groupPosition)
.getArrayList().get(childPosition).getValue());
else
childViewHolder.et.setText("");
childViewHolder.et.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus){
final EditText Caption = (EditText) v;
groupItem.get(groupPosition)
.getArrayList().get(childPosition).setValue(Caption.
getText().toString());
}
});
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
private class GroupViewHolder {
public TextView groupTitle;
}
private class ChildViewHolder {
public TextView childTitle;
public EditText et;
}
}
The model class
public class ListItemModel {
String title;
ArrayList<EdittextValues> arrayList = new ArrayList<>();
public ListItemModel(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public ArrayList<EdittextValues> getArrayList() {
return arrayList;
}
public void setArrayList(ArrayList<EdittextValues> arrayList) {
this.arrayList = arrayList;
}
}
The pojo class
public class EdittextValues {
String value;
public EdittextValues(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
The activity class
public class ShelfCheckActivity extends AppCompatActivity implements
SearchView.OnQueryTextListener {
private ExpandableListView expandableListView;
ShelfCheckAdapter shelfCheckAdapter;
ArrayList<ListItemModel> listItemModels;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shelf_check);
// initializing the views
initViews();
// preparing list data
//initListData();
}
/**
* method to initialize the views
*/
private void initViews() {
expandableListView = findViewById(R.id.listview);
initListData();
shelfCheckAdapter = new
ShelfCheckAdapter(listItemModels,ShelfCheckActivity.this);
shelfCheckAdapter
.setInflater((LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE));
expandableListView
.setAdapter(shelfCheckAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_store_check, menu);
MenuItem menuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) menuItem.getActionView();
searchView.setOnQueryTextListener(this);
return true;
}
private void initListData() {
ArrayList<EdittextValues> edittextValues = new ArrayList<>();
ArrayList<String> childTitle = new ArrayList<>();
childTitle.add("Product a");
childTitle.add("Product b");
childTitle.add("Product c");
childTitle.add("Product d");
childTitle.add("Product e");
childTitle.add("Product f");
childTitle.add("Product g");
childTitle.add("Product h");
childTitle.add("Product i");
childTitle.add("Product j");
childTitle.add("Product k");
childTitle.add("Product l");
for(int i = 0; i < childTitle.size(); i++)
{
edittextValues.add(new EdittextValues(""));
}
listItemModels = new ArrayList<>();
listItemModels.add(new ListItemModel("Product
1",edittextValues,childTitle));
listItemModels.add(new ListItemModel("Product
2",edittextValues,childTitle));
listItemModels.add(new ListItemModel("Product
3",edittextValues,childTitle));
listItemModels.add(new ListItemModel("Product
4",edittextValues,childTitle));
listItemModels.add(new ListItemModel("Product
5",edittextValues,childTitle));
listItemModels.add(new ListItemModel("Product
6",edittextValues,childTitle));
}
#Override
public boolean onQueryTextSubmit(String s) {
return false;
}
#Override
public boolean onQueryTextChange(String s) {
return false;
}
}
enter image description here
Just change below methods and check its working or not!
#Override
public View getChildView(int groupPosition, int childPosition, boolean
isLastChild, View convertView, ViewGroup parent) {
if(convertView == null)
{
convertView = LayoutInflater.from(context).inflate(R.layout.list_row_child,null);
childViewHolder = new ChildViewHolder(convertView, groupPosition, childPosition);
convertView.setTag(childViewHolder);
}
else{
childViewHolder = (ChildViewHolder) convertView.getTag();
}
childViewHolder.childTitle.setText(groupItem.get(groupPosition)
.getChildTitles().get(childPosition));
return convertView;
}
Another change is
private class ChildViewHolder {
public TextView childTitle;
public EditText et;
public ChildViewHolder(View itemView, int groupPosition, int childPosition) {
super(itemView);
childTitle = itemView.findViewById(R.id.textViewChild);
et = itemView.findViewById(R.id.productCount);
et.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(charSequence != null){
groupItem.get(groupPosition).getArrayList().get(childPosition).setValue(charSequence.toString());
}
}
#Override
public void afterTextChanged(Editable editable) {
}
});
}
}

Clear All button doesn't uncheck all boxes in a ExpandableListView android?

I am using checkboxes in all child view elements in ExpandableListView. To clear all checkboxes in one go, I am using a button clearFilters and the code for the Adapter class and the button click event is below.
Clicking the button doesn't do anything at all. I want to clear all checkboxes when the button is clicked.Any help is greatly appreciated.
ExpandableListAdapterClass:
public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> expandableListTitle;
private Map<String, List<ChildViewModel>> expandableListDetail;
private static List<ChildViewHolder> checkedViewHolders=new ArrayList<>();
static int checkedBoxesCount;
public ExpandableListViewAdapter(Context context, List<String> expandableListTitle, Map<String,
List<ChildViewModel>> expandableListDetail) {
this.context = context;
this.expandableListTitle = expandableListTitle;
this.expandableListDetail = expandableListDetail;
}
#Override
public int getGroupCount() {
return expandableListTitle.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return expandableListDetail.get(expandableListTitle.get(groupPosition)).size();
}
#Override
public String getGroup(int groupPosition) {
return expandableListTitle.get(groupPosition);
}
#Override
public ChildViewModel getChild(int groupPosition, int childPosition) {
return expandableListDetail.get(expandableListTitle.get(groupPosition)).get(childPosition);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean b, View view, ViewGroup viewGroup) {
String listTitle=getGroup(groupPosition);
GroupViewHolder groupViewHolder;
if(view==null){
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(R.layout.expanded_list_group,null);
groupViewHolder=new GroupViewHolder();
groupViewHolder.listTitleTextView=(TextView)view.findViewById(R.id.txtExpandedListTitle);
view.setTag(groupViewHolder);
}else {
groupViewHolder=(GroupViewHolder)view.getTag();
}
groupViewHolder.listTitleTextView.setText(listTitle);
return view;
}
#Override
public View getChildView(final int groupPosition, final int childPosition, boolean b, View view, ViewGroup viewGroup) {
final ChildViewModel expandedListText=getChild(groupPosition,childPosition);
final ChildViewHolder childViewHolder;
if(view==null){
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(R.layout.expanded_list_item,null);
childViewHolder=new ChildViewHolder();
childViewHolder.expandedListTextView=(TextView)view.findViewById(R.id.txtExpandedListItem);
childViewHolder.checkBox=(CheckBox)view.findViewById(R.id.expandeditem_chkbox);
view.setTag(childViewHolder);
}else {
childViewHolder=(ChildViewHolder)view.getTag();
}
childViewHolder.expandedListTextView.setText(expandedListText.getName());
if(expandedListText.isCheckStatus()){
childViewHolder.checkBox.setChecked(true);
}else {
childViewHolder.checkBox.setChecked(false);
}
childViewHolder.checkBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ChildViewModel model;
if(childViewHolder.checkBox.isChecked()){
checkedBoxesCount++;
model=expandableListDetail.get(expandableListTitle.get(groupPosition)).get(childPosition);
model.setCheckStatus(true);
expandableListDetail.get(expandableListTitle.get(groupPosition)).set(childPosition,model);
checkedViewHolders.add(childViewHolder);
notifyDataSetChanged();
Toast.makeText(context,"Checked value is"+expandableListDetail.get(expandableListTitle.get(groupPosition)).get(childPosition),Toast.LENGTH_SHORT).show();
}else {
checkedBoxesCount--;
if(checkedBoxesCount==0){
Toast.makeText(context,"nothing checked",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context,"unchecked",Toast.LENGTH_SHORT).show();
}
model=expandableListDetail.get(expandableListTitle.get(groupPosition)).get(childPosition);
model.setCheckStatus(false);
checkedViewHolders.remove(childViewHolder);
expandableListDetail.get(expandableListTitle.get(groupPosition)).set(childPosition,model);
notifyDataSetChanged();
}
}
});
return view;
}
public void clearChecks(){
for(int i=0;i<checkedViewHolders.size();i++){
checkedViewHolders.get(i).checkBox.setChecked(false);
notifyDataSetChanged();
}
checkedViewHolders.clear();
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public class GroupViewHolder {
TextView listTitleTextView;
}
public class ChildViewHolder {
TextView expandedListTextView;
CheckBox checkBox;
}
}
Here is the MainActivity class:
public class MainActivity extends AppCompatActivity {
ExpandableListView mExpandableListView;
ExpandableListViewAdapter mExpandableListAdapter;
Button clearFilters;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mExpandableListView=(ExpandableListView)findViewById(R.id.expandedListView);
clearFilters=(Button)findViewById(R.id.btnClearFilter);
mExpandableListAdapter=new ExpandableListViewAdapter(MainActivity.this,getTitles(),getNames());
mExpandableListView.setAdapter(mExpandableListAdapter);
clearFilters.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mExpandableListAdapter.clearChecks();
}
});
}
}
If the motive is to simply uncheck all checkboxes, we can use this technique to iterate through the Hashmap and set all checked status to false. It will clear all checkboxes in all childViews.
public void clearChecks(){
for (List<ChildViewModel> value:expandableListDetail.values()) {
for(ChildViewModel sample:value){
sample.setCheckStatus(false);
}
}
notifyDataSetChanged();

Check if atleast one checkbox item from every child view in an expandable listview is selected

I have an Expandable ListView. Something like this.
Now I have to enable the continue button only when at least one item is selected from every row. Is that possible to check?
The xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fb="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/expandableListViewCreateProfileFecets"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="#dimen/size_small"
android:layout_marginLeft="#dimen/size_medium"
android:layout_marginRight="#dimen/size_medium"
android:layout_marginTop="#dimen/size_small"
android:layout_weight="1"
android:divider="#null"
android:dividerHeight="0dp"
android:groupIndicator="#null" />
<Button
android:id="#+id/buttonContinue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/size_medium"
android:background="#color/layoutGrey"
android:enabled="true"
android:letterSpacing="0.1"
android:padding="#dimen/size_large"
android:text="#string/button_continue"
android:textColor="#color/white" />
</LinearLayout>
Group Adapter
public class CreateProfileExpandableAdapter extends BaseExpandableListAdapter {
ArrayList<CreateProfileFacetsHeaderModel> al;
Activity activity;
public CreateProfileExpandableAdapter(Activity activity, ArrayList<CreateProfileFacetsHeaderModel> al) {
this.activity = activity;
this.al = al;
LinksAndKeys.arrayListSelectedFecets = al;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return al.get(groupPosition).getValues();
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return al.get(groupPosition).hashCode();
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
String viewType = al.get(groupPosition).getAppearance();
if (v == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.create_profile_child_grid, parent, false);
}
ExpandableHeightGridView gridViewChildren = (ExpandableHeightGridView) v.findViewById(R.id.gridViewChildren);
gridViewChildren.setExpanded(true);
if (viewType.equalsIgnoreCase(LinksAndKeys.SIZE_LIST_KEY)) {
gridViewChildren.setNumColumns(5);
CreateProfileChildAdapterGrid createProfileChildAdapter = new CreateProfileChildAdapterGrid(activity, al.get(groupPosition).getValues(), groupPosition);
gridViewChildren.setAdapter(createProfileChildAdapter);
} else if (viewType.equalsIgnoreCase(LinksAndKeys.STYLES_LIST_KEY)) {
gridViewChildren.setNumColumns(1);
CreateProfileChildAdapterCheckBox createProfileChildAdapter = new CreateProfileChildAdapterCheckBox(activity, al.get(groupPosition).getValues(), groupPosition);
gridViewChildren.setAdapter(createProfileChildAdapter);
}
return v;
}
#Override
public int getChildrenCount(int groupPosition) {
return 1;
}
#Override
public Object getGroup(int groupPosition) {
return al.get(groupPosition);
}
#Override
public int getGroupCount() {
return al.size();
}
#Override
public long getGroupId(int groupPosition) {
return al.get(groupPosition).hashCode();
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.create_profile_group, parent, false);
}
TextView textViewGroup = (TextView) v.findViewById(R.id.textViewGroup);
ImageView imageViewExpanded = (ImageView) v.findViewById(R.id.imageViewExpanded);
textViewGroup.setText(al.get(groupPosition).getTitle());
if (isExpanded)
imageViewExpanded.setImageResource(R.drawable.minus);
else
imageViewExpanded.setImageResource(R.drawable.plus);
return v;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Child Adapter:
public class CreateProfileChildAdapterGrid extends BaseAdapter {
Activity activity;
ArrayList<CreateProfileFacetsChildModel> al;
int index = -1;
int groupPosition;
public CreateProfileChildAdapterGrid(Activity activity, ArrayList<CreateProfileFacetsChildModel> al, int groupPosition) {
// TODO Auto-generated constructor stub
this.activity = activity;
this.al = al;
this.groupPosition = groupPosition;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return al.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return al.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
private static class ViewHolder {
CheckBox checkBoxChild;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(activity);
convertView = inflater.inflate(R.layout.create_profile_grid_child, parent, false);
viewHolder = new ViewHolder();
viewHolder.checkBoxChild = (CheckBox) convertView.findViewById(R.id.checkBoxChild);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.checkBoxChild.setText(al.get(position).getDefaultValue());
viewHolder.checkBoxChild.setChecked(al.get(position).isSelected());
if (al.get(position).isSelected())
viewHolder.checkBoxChild.setTextColor(ContextCompat.getColor(activity, R.color.white));
else
viewHolder.checkBoxChild.setTextColor(ContextCompat.getColor(activity, R.color.black));
viewHolder.checkBoxChild.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
al.get(position).setSelected(b);
LinksAndKeys.arrayListSelectedFecets.get(groupPosition).getValues().get(position).setSelected(b);
if (b) {
viewHolder.checkBoxChild.setTextColor(ContextCompat.getColor(activity, R.color.white));
} else {
viewHolder.checkBoxChild.setTextColor(ContextCompat.getColor(activity, R.color.black));
}
}
});
return convertView;
}
}

3 level expandable listview 3rd level truncated

apologies for the code dump - if you prefer the github version this is the code I'm working from:
https://github.com/Barbelos/ThreeLevelExpandableListVIew
The list is working fine except for one thing - the only way I could figure to set the height in onMeasure was by measuring the size of the RelativeLayout the list expands into - so if the list is bigger than the screen you can scroll it.
For some reason (I don't really understand the code), the second level expands fine - you can put as many items in there and it will just expand to fit. The problem happens on the third level - the items get truncated at what looks to me like the height of the screen. They're still there - if you hold down on some other part of the screen you can scroll the third level, but that's not very intuitive. Can anybody see a way to make this work? I've tried changing the xml but got nowhere, and MeasureSpec.UNSPECIFIED seems to do the exact opposite of what I'm trying to do...
MainActivity.java:
package com.example.threeleveltest;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.widget.ExpandableListView;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
public static CustomExpandableListView list;
static int ht;
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus == true) {
RelativeLayout parent= (RelativeLayout) findViewById(R.id.parent);
ht = parent.getHeight();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int noObjectsLevel1= 15;
int noObjectsLevel2= 24;
int noObjectsLevel3= 57;
List<Object> objectsLvl1= new ArrayList<Object>();
for (int i=0; i<noObjectsLevel1; i++) {
List<Object> objectsLvl2= new ArrayList<Object>();
for (int j=0; j<noObjectsLevel2; j++) {
List<Object> objectsLvl3= new ArrayList<Object>();
for (int k=0; k<noObjectsLevel3; k++) {
objectsLvl3.add(new Object("lvl3_"+String.valueOf(k), null));
}
objectsLvl2.add(new Object("lvl2_"+String.valueOf(j), objectsLvl3));
}
objectsLvl1.add(new Object("lvl1_"+String.valueOf(i), objectsLvl2));
}
RelativeLayout parent= (RelativeLayout) findViewById(R.id.parent);
list= new CustomExpandableListView(this);
Adapter adapter= new Adapter(this, objectsLvl1);
list.setAdapter(adapter);
parent.addView(list);
}
}
class CustomExpandableListView extends ExpandableListView {
public CustomExpandableListView(Context context) {
super(context);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
/*
* Adjust height
*/
int h=MainActivity.ht;
heightMeasureSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
Adapter.java:
package com.example.threeleveltest;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
public class Adapter extends BaseExpandableListAdapter {
private List<Object> objects;
private Activity activity;
private LayoutInflater inflater;
public Adapter(Activity activity, List<Object> objects) {
this.objects= objects;
this.activity= activity;
this.inflater= (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return objects.get(groupPosition).getObjects().get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Object object= (Object) getChild(groupPosition, childPosition);
CustomExpandableListView subObjects= (CustomExpandableListView) convertView;;
if (convertView==null) {
subObjects= new CustomExpandableListView(activity);
}
Adapter2 adapter= new Adapter2(activity, object);
subObjects.setAdapter(adapter);
return subObjects;
}
#Override
public int getChildrenCount(int groupPosition) {
return objects.get(groupPosition).getObjects().size();
}
#Override
public Object getGroup(int groupPosition) {
return objects.get(groupPosition);
}
#Override
public int getGroupCount() {
return objects.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Object object= (Object) getGroup(groupPosition);
if (convertView==null) {
convertView= inflater.inflate(R.layout.listview_element, null);
}
TextView name= (TextView) convertView.findViewById(R.id.name);
name.setText(object.getName());
return convertView;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
class Adapter2 extends BaseExpandableListAdapter {
private Object object;
private LayoutInflater inflater;
private Activity activity;
public Adapter2(Activity activity, Object object) {
this.activity= activity;
this.object= object;
this.inflater= (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return object.getObjects().get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Object object= (Object) getChild(0, childPosition);
if (convertView==null) {
convertView= inflater.inflate(R.layout.listview_element, null);
Resources r = activity.getResources();
float px40 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, r.getDisplayMetrics());
convertView.setPadding(
convertView.getPaddingLeft() + (int) px40,
convertView.getPaddingTop(),
convertView.getPaddingRight(),
convertView.getPaddingBottom());
}
TextView name= (TextView) convertView.findViewById(R.id.name);
name.setText(object.getName());
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return object.getObjects().size();
}
#Override
public Object getGroup(int groupPosition) {
return object;
}
#Override
public int getGroupCount() {
return 1;
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView==null) {
convertView= inflater.inflate(R.layout.listview_element, null);
Resources r = activity.getResources();
float px20 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, r.getDisplayMetrics());
convertView.setPadding(
convertView.getPaddingLeft() + (int) px20,
convertView.getPaddingTop(),
convertView.getPaddingRight(),
convertView.getPaddingBottom());
}
TextView name= (TextView) convertView.findViewById(R.id.name);
name.setText(object.getName());
return convertView;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Object.java:
package com.example.threeleveltest;
import java.util.List;
public class Object {
String name;
List<Object> objects;
public Object(String name, List<Object> objects) {
this.name= name;
this.objects= objects;
}
public String getName() {
return this.name;
}
public List<Object> getObjects() {
return this.objects;
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
</RelativeLayout>
listview_element.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="40dp"
android:paddingLeft="40dp" />
</RelativeLayout>
This isn't much of an answer, more of a workaround, really, but I post it here in case anybody comes up against the same problem in future - I'm not nearly smart enough to solve the original problem, so I ended up just using a standard two-level expandable list, and when you click on the 2nd level it brings up a dialog with a listview of the third level items. Looks ok - actually works better on small screens, and you can add as many items as you like.
I'm too late but I hope this can help other people with the same issue. The way I fixed this was to increase the size in makeMeasureSpec() in CustomExpandableView to a very large number. It really depends on how many items you wanna show on the 3rd level.
heightMeasureSpec = MeasureSpec.makeMeasureSpec(5000, MeasureSpec.AT_MOST);

ExpandableListView OnChildClickListener doesn't work

Adapter
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ExpandableListView mExpandableListView;
private List <Grupe> mGroupCollection;
private int[] groupStatus;
public ExpandableListAdapter() {}
public ExpandableListAdapter(Context pContext,
ExpandableListView pExpandableListView,
List <Grupe> pGroupCollection) {
mContext = pContext;
mGroupCollection = pGroupCollection;
mExpandableListView = pExpandableListView;
groupStatus = new int[mGroupCollection.size()];
setListEvent();
}
private void setListEvent() {
mExpandableListView
.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int arg0) {
groupStatus[arg0] = 1;
}
});
mExpandableListView
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int arg0) {
groupStatus[arg0] = 0;
}
});
}
#Override
public String getChild(int arg0, int arg1) {
return mGroupCollection.get(arg0).getChildren().get(arg0).getPrimaoc_Poruke();
}
#Override
public long getChildId(int arg0, int arg1) {
return 0;
}
#Override
public View getChildView(int arg0, int arg1, boolean arg2, View arg3,
ViewGroup arg4) {
ChildHolder childHolder;
if (arg3 == null) {
arg3 = LayoutInflater.from(mContext).inflate(
R.layout.list_group_item, null);
childHolder = new ChildHolder();
childHolder.title = (TextView) arg3.findViewById(R.id.item_title);
arg3.setTag(childHolder);
} else {
childHolder = (ChildHolder) arg3.getTag();
}
childHolder.title.setText(mGroupCollection.get(arg0).getChildren().get(arg1).getPrimaoc_Poruke());
return arg3;
}
#Override
public int getChildrenCount(int arg0) {
return mGroupCollection.get(arg0).getChildren().size();
}
#Override
public Object getGroup(int arg0) {
return mGroupCollection.get(arg0);
}
#Override
public int getGroupCount() {
return mGroupCollection.size();
}
#Override
public long getGroupId(int arg0) {
return arg0;
}
#Override
public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {
GroupHolder groupHolder;
if (arg2 == null) {
arg2 = LayoutInflater.from(mContext).inflate(R.layout.list_group, null);
groupHolder = new GroupHolder();
groupHolder.img = (ImageView) arg2.findViewById(R.id.tag_img);
groupHolder.title = (TextView) arg2.findViewById(R.id.group_title);
arg2.setTag(groupHolder);
} else {
groupHolder = (GroupHolder) arg2.getTag();
}
if (groupStatus[arg0] == 0) {
groupHolder.img.setImageResource(R.drawable.group_down);
} else {
groupHolder.img.setImageResource(R.drawable.group_up);
}
groupHolder.title.setText(mGroupCollection.get(arg0).getTip());
return arg2;
}
class GroupHolder {
ImageView img;
TextView title;
}
class ChildHolder {
TextView title;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}
MainActivity
public class Glavna extends Activity implements OnClickListener, OnChildClickListener {
private List <Grupe> mGroupCollection;
private ExpandableListView mExpandableListView;
private ExpandableListAdapter adapter = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_glavna);
prepareResource();
initPage();
}
private void initPage() {
mExpandableListView = (ExpandableListView) findViewById(R.id.expandableListView1);
adapter = new ExpandableListAdapter(this,mExpandableListView, mGroupCollection);
mExpandableListView.setAdapter(adapter);
mExpandableListView.setOnChildClickListener(this);
}
private void prepareResource() {
mGroupCollection = new ArrayList <Grupe> ();
ge.setTip("Online korisnici");
mGroupCollection.add(ge);
AktivniChat gi = new AktivniChat(1, "receiver 1", new Korisnik(1, "sender1"));
mGroupCollection.get(0).setAktivniChat(gi);
}
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
return true;
}
}
Set android:focusable="false" on all elements.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:paddingTop="5dip"
android:focusable="false">
<LinearLayout
android:id="#+id/groupItem"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#FFF385"
android:clickable="false"
android:focusable="false">
<TextView
android:id="#+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF84"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="sample"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Don't forget to enable child Selectable property..
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
It worked for me too... All items in layout (of the child) must be set to focusable="false" and clickable="false". But if you have buttons in child layout this will not work.

Categories