package com.myhotel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.TextView;
public class CustomOrderEListAdapter extends BaseExpandableListAdapter {
Context context;
ArrayList<String> hotelsRecipeList;
HashMap<String, List<String>> hotelsRecipeItemList;
public CustomOrderEListAdapter(OrderActivity orderActivity,
ArrayList<String> hotelsRecipeList,
HashMap<String, List<String>> hotelsRecipeItemList) {
this.context = orderActivity;
this.hotelsRecipeList = hotelsRecipeList;
this.hotelsRecipeItemList = hotelsRecipeItemList;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return hotelsRecipeItemList.get(hotelsRecipeList.get(groupPosition))
.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
//this Map is used for storing checkbox object for checking purpose
Map<String, CheckBox> chkMap=new Hashtable<String, CheckBox>();
@Override
public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent)
{
String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_child, null);
}
TextView textOrderChildItemName = (TextView) convertView.findViewById(R.id.textOrderChildItemName);
CheckBox chkOrderItem = (CheckBox) convertView.findViewById(R.id.chkOrderItem);
chkMap.put(groupPosition+","+childPosition, chkOrderItem);
textOrderChildItemName.setText(childText);
//Toast.makeText(context, "size"+chkMap.size(),Toast.LENGTH_LONG).show();
return convertView;
}
@Override
public int getChildrenCount(int groupPosition)
{
return hotelsRecipeItemList.get(hotelsRecipeList.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition)
{
return hotelsRecipeList.get(groupPosition);
}
@Override
public int getGroupCount()
{
return hotelsRecipeList.size();
}
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent)
{
String groupText = (String) getGroup(groupPosition);
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_group, null);
}
TextView textOrderRecipeName = (TextView) convertView.findViewById(R.id.textOrderRecipeName);
textOrderRecipeName.setText(groupText);
//Toast.makeText(context, "size"+chkMap.size(),Toast.LENGTH_LONG).show();
return convertView;
}
@Override
public boolean hasStableIds()
{
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
CheckBox chk=(CheckBox) chkMap.get(groupPosition+","+childPosition);
if(chk.isChecked())
{
chk.setChecked(false);
//Toast.makeText(context, "false",Toast.LENGTH_LONG).show();
}
else
{
chk.setChecked(true);
//Toast.makeText(context, "true",Toast.LENGTH_LONG).show();
}
//Toast.makeText(context, "group- >"+groupPosition+"child=>"+childPosition,Toast.LENGTH_LONG).show();
return true;
}
}
hello friends ,i have added one textview and one check box as a child row in expandablelistview i when am selecting only one checkbox in expandablelistview then other checkbox automatically selecting , which are i don't want to select, i mean when i select any particular chaeckbox that only should be selecting, please help me. thanks in advance
0 comments:
Post a Comment