Android expanablelistview(在组视图和子视图中)中的“如何执行”复选框
我正在尝试在expanablelistview(在groupview和child视图中)中选中复选框。但我不理解这个概念。 所以伙计们,如果你们有任何想法,请和我分享。 这是我第一次使用这个概念(expanablelistview) 组视图中的复选框(复选框组)Android expanablelistview(在组视图和子视图中)中的“如何执行”复选框,android,android-layout,android-intent,android-emulator,android-contentprovider,Android,Android Layout,Android Intent,Android Emulator,Android Contentprovider,我正在尝试在expanablelistview(在groupview和child视图中)中选中复选框。但我不理解这个概念。 所以伙计们,如果你们有任何想法,请和我分享。 这是我第一次使用这个概念(expanablelistview) 组视图中的复选框(复选框组) 如果我选中groupview(groupposition 0)中的复选框,则子项(childposition 0)中的所有项都必须选中 与取消选中groupview(groupposition 0)相同,子项(childposition
public class DetailAdapter extends BaseExpandableListAdapter {
private LayoutInflater mInflater;
private ArrayList<PatientSampleDetails> sampleArray;
private ArrayList<lstServiceOrderDetails> serviceLst;
private Activity activity;
ArrayAdapter<String> adapter;
View row;
public LayoutInflater minflater;
Context mContext;
int chldPosition;
// ServiceOrderList elementChild
PatientSampleDetails elementChild;
public static HashMap<Integer,Boolean> selectedGroupMembers = new HashMap<Integer, Boolean>();
private static View container ;
ActionItem nextItem;
int posi;
lstServiceOrderDetails child;
View rowView;
static class ViewHolder {
private CheckBox checkBoxChild;
public CheckBox checkBoxGroup;
public Button button;
public TextView service;
}
public WorkDetailAdapter(Activity activity, ArrayList<PatientSampleDetails> sampleArray) {
this.sampleArray = sampleArray;
this.activity = activity;
mInflater = LayoutInflater.from(activity);
}
public void setInflater(LayoutInflater mInflater) {
this.minflater = mInflater;
}
public Object getChild(int groupPosition, int childPosition) {
return sampleArray.get(groupPosition).lstServiceOrderDetails.get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
Log.i("getChildView-getChild", groupPosition + "/" + childPosition);
child = (lstServiceOrderDetails) getChild(groupPosition, childPosition);
Log.i("child", "child data"+ child.getServiceName());
rowView = convertView;
final ViewHolder holder = new ViewHolder();
if (convertView == null) {
convertView = mInflater.inflate(R.layout.detaillistrowview, null);
holder.serviceText = (TextView) convertView.findViewById(R.id.sevice);
holder.checkBoxChild = (CheckBox)convertView.findViewById(R.id.checkBox);
holder.checkBoxChild.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
elementChild = (PatientSampleDetails) holder.checkBoxChild.getTag();
elementChild.setSelected(buttonView.isChecked());
Log.i("buttonView-checkBox", "getChildId :" + getChildId(groupPosition, childPosition));
Log.i("status", ""+ elementChild.isSelected());
} else {
elementChild.setSelected(false);
}
}
});
if (selectedGroupMembers.containsKey(groupPosition) == true){
holder.checkBoxChild.setActivated(true);
Log.i("true", "true");
holder.checkBoxChild.setSelectAllOnFocus(true);
} else {
holder.checkBoxChild.setActivated(false);
Log.i("false", "false");
holder.checkBoxChild.setSelectAllOnFocus(true);
}
convertView.setTag(holder);
holder.checkBoxChild.setTag(sampleArray.get(groupPosition));
holder.serviceText.setText(Util.formatN2H(child.getServiceName()));
Log.i("child", "child data ---> "+ child.getServiceName() +"/"+child.getServiceName());
//Now write here code for set colors for rows
/* if(childPosition % 2 == 0) {
convertView.setBackgroundColor(Color.parseColor("#E7E8E8"));
} else {
convertView.setBackgroundColor(Color.parseColor("#C9CACC"));
}*/
// To change the color of the Listview row.
// / convertView.setBackgroundColor((childPosition & 1) == 1 ? Color.parseColor("#E7E8E8") : Color.parseColor("#C9CACC"));
return convertView;
}
public int getChildrenCount(int groupPosition) {
serviceLst = sampleArray.get(groupPosition).getServiceOrderList();
return serviceLst.size();
}
public Object getGroup(int groupPosition) {
return sampleArray.get(groupPosition);
}
public int getGroupCount() {
return sampleArray.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
final ViewHolder holder = new ViewHolder();
PatientSampleDetails group = (PatientSampleDetails) getGroup(groupPosition);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.getgroupviewdetail, null);
convertView.setId(groupPosition);
holder.checkBoxGroup = (CheckBox) convertView.findViewById(R.id.checkBoxGroup);
holder.checkBoxGroup.setFocusable(false);
holder.checkBoxGroup.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
PatientSampleDetails elementGroup ;
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked == true) {
selectedGroupMembers.put(groupPosition, Boolean.valueOf(true)); //new Boolean(true));
elementGroup = (PatientSampleDetails) holder.checkBoxGroup.getTag();
elementGroup.setSelected(buttonView.isChecked());
Log.i("Clicked : ", "group" + groupPosition);
Log.i("buttonView", "getItemId :" + getGroupId(groupPosition));
Log.i("status", ""+ elementGroup.isSelected());
Log.i("buttonView", "chldPosition :" + getChildId(groupPosition, chldPosition));
notifyDataSetChanged();
} else if (selectedGroupMembers.containsKey(groupPosition)) {
selectedGroupMembers.remove(groupPosition);
elementGroup.setSelected(false);
Log.i(" Removed : ", "group" + groupPosition);
notifyDataSetChanged();
}
}
});
convertView.setTag(holder);
holder.checkBoxGroup.setTag(sampleArray.get(groupPosition));
} else {
((ViewHolder) convertView.getTag()).checkBoxGroup.setTag(sampleArray.get(groupPosition));
}
return convertView;
}
public boolean hasStableIds() {
return false;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
公共类DetailAdapter扩展了BaseExpandableListAdapter{
私人停车场;
私有数组列表样本数组;
私有ArrayList服务;
私人活动;
阵列适配器;
查看行;
公共布局更扁平,更扁平;
语境;
内衣原体位置;
//ServiceOrderList元素子对象
PatientsSampleDetails元素儿童;
public static HashMap selectedGroupMembers=new HashMap();
私有静态视图容器;
行动项目nextItem;
int-posi;
lstServiceOrderDetails子项;
视图行视图;
静态类视窗夹{
私有复选框checkBoxChild;
公共复选框复选框组;
公共按钮;
公共文本浏览服务;
}
公共WorketailAdapter(活动活动,ArrayList sampleArray){
this.sampleArray=sampleArray;
这个。活动=活动;
mInflater=LayoutFlater.from(活动);
}
公共空间设置充气机(LAYOUTINGER mInflater){
this.minflater=minflater;
}
公共对象getChild(int-groupPosition,int-childPosition){
返回sampleArray.get(groupPosition).lstServiceOrderDetails.get(childPosition);
}
公共长getChildId(int-groupPosition,int-childPosition){
返回子位置;
}
公共视图getChildView(最终整数组位置、最终整数子位置、布尔isLastChild、视图转换视图、视图组父级){
Log.i(“getChildView getChild”,groupPosition+“/”+childPosition);
child=(lstServiceOrderDetails)getChild(groupPosition,childPosition);
Log.i(“child”,“child data”+child.getServiceName());
rowView=convertView;
最终视图持有者=新的视图持有者();
if(convertView==null){
convertView=mInflater.inflate(R.layout.detaillistrowview,null);
holder.serviceText=(TextView)convertView.findViewById(R.id.sevice);
holder.checkBoxChild=(复选框)convertView.findViewById(R.id.CheckBox);
holder.checkBoxChild.setOnCheckedChangeListener(新的CompoundButton.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(复合按钮视图,布尔值已检查){
如果(已检查){
elementChild=(PatientSampleDetails)holder.checkBoxChild.getTag();
elementChild.setSelected(buttonView.isChecked());
Log.i(“buttonView复选框”,“getChildId:+getChildId(groupPosition,childPosition));
Log.i(“status”,“”+elementChild.isSelected());
}否则{
elementChild.setSelected(假);
}
}
});
if(selectedGroupMembers.containsKey(groupPosition)==true){
holder.checkBoxChild.setActivated(真);
Log.i(“真”、“真”);
holder.checkBoxChild.setSelectAllOnFocus(真);
}否则{
holder.checkBoxChild.setActivated(假);
Log.i(“假”、“假”);
holder.checkBoxChild.setSelectAllOnFocus(真);
}
convertView.setTag(支架);
holder.checkBoxChild.setTag(sampleArray.get(groupPosition));
holder.serviceText.setText(Util.formatN2H(child.getServiceName());
Log.i(“child”,“child data-->”+child.getServiceName()+“/”+child.getServiceName());
//现在在这里为行设置颜色编写代码
/*如果(子位置%2==0){
convertView.setBackgroundColor(Color.parseColor(“#E7E8E8”);
}否则{
convertView.setBackgroundColor(Color.parseColor(#C9CACC));
}*/
//更改Listview行的颜色。
///convertView.setBackgroundColor((childPosition&1)=1?Color.parseColor(“#E7E8E8”):Color.parseColor(#C9CACC”);
返回视图;
}
公共整数getChildrenCount(整数组位置){
serviceLst=sampleArray.get(groupPosition.getServiceOrderList();
返回serviceLst.size();
}
公共对象getGroup(int-groupPosition){
返回sampleArray.get(groupPosition);
}
public int getGroupCount(){
返回sampleArray.size();
}
公共长getGroupId(int-groupPosition){
返回组位置;
}
公共视图getGroupView(最终int groupPosition、布尔值isExpanded、视图convertView、视图组父级){
最终视图持有者=新的视图持有者();
PatientSampleDetails组=(PatientSampleDetails)getGroup(groupPosition);
if(convertView==null){
convertView=mInflater.inflate(R.layout.getgroupviewdetail,null);
convertView.setId(groupPosition);
holder.checkBoxGroup=(复选框)convertView.findViewById(R.id.checkBoxGroup);
holder.checkBoxGroup.se
if (convertView == null) {
//Add ur code
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}