Android 自定义Expandablelistview取消排序数据
我有一个可扩展的Listview,其中包含存储在列表和Hashmap中的数据。我的问题是,当我折叠并展开一个组时,可展开的listview会显示未排序的数据。我快疯了Android 自定义Expandablelistview取消排序数据,android,expandablelistview,expandablelistadapter,Android,Expandablelistview,Expandablelistadapter,我有一个可扩展的Listview,其中包含存储在列表和Hashmap中的数据。我的问题是,当我折叠并展开一个组时,可展开的listview会显示未排序的数据。我快疯了 import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; import android.content.Context; import andr
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Filter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.pebbo.yaa.R;
public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<PojoAlgCat> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<PojoAlgCat, List<PojoAlg>> _listDataChild;
Integer[] Algs_lite = {5, 19};
Integer[] Algs_cat_lite = {1, 2};
LinearLayout ll_row, ll_row_child;
TextView lblListHeader;
TextView txtListChild;
public CustomExpandableListAdapter(Context context, List<PojoAlgCat> listDataHeader,
HashMap<PojoAlgCat, List<PojoAlg>> 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);
}
public Object getChildTitle(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosititon).getName();
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosition).getId();
}
public int getCatId(int groupPosition) {
return this._listDataHeader.get(groupPosition).getId();
}
public int getAlgId(int groupPosition, int childPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosition).getId();
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChildTitle(groupPosition, childPosition);
boolean exists = containsValue(Algs_lite, getAlgId(groupPosition, childPosition));
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
ll_row_child = (LinearLayout) convertView.findViewById(R.id.ll_row_child);
txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
if(exists){
//Log.i("Adapter1", "VALUE:::" + exists + ":::ID:::" + f.getId() + ":::NAME:::" + f.getName() + ":::DISPONIBLE");
ll_row_child.setBackgroundColor(Color.WHITE);
txtListChild.setTextColor(_context.getResources().getColor(R.color.DarkBlueBG));
}else{
//Log.e("Adapter1", "VALUE:::" + exists + ":::ID:::" + f.getId() + ":::NAME:::" + f.getName() + ":::NO DISPONIBLE");
ll_row_child.setBackgroundColor(Color.LTGRAY);
txtListChild.setTextColor(Color.GRAY);
}
}
txtListChild.setText(childText);
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);
}
public Object getGroupTitle(int groupPosition) {
return this._listDataHeader.get(groupPosition).getCategory();
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return this._listDataHeader.get(groupPosition).getId();
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroupTitle(groupPosition);
boolean exists_alg = containsValue(Algs_cat_lite, getCatId(groupPosition));
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
ll_row = (LinearLayout) convertView.findViewById(R.id.ll_row);
lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
if(exists_alg){
//Log.i("Adapter1", "VALUE:::" + exists + ":::ID:::" + f.getId() + ":::NAME:::" + f.getName() + ":::DISPONIBLE");
ll_row.setBackgroundColor(_context.getResources().getColor(R.color.BlueBG));
lblListHeader.setTextColor(Color.WHITE);
}else{
//Log.e("Adapter1", "VALUE:::" + exists + ":::ID:::" + f.getId() + ":::NAME:::" + f.getName() + ":::NO DISPONIBLE");
ll_row.setBackgroundColor(_context.getResources().getColor(R.color.DimGray));
lblListHeader.setTextColor(_context.getResources().getColor(R.color.LightGrey));
}
}
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public static boolean containsValue(Integer[] arr, Integer targetValue) {
Set<Integer> set = new HashSet<Integer>(Arrays.asList(arr));
return set.contains(targetValue);
}
}
导入java.util.array;
导入java.util.HashMap;
导入java.util.HashSet;
导入java.util.List;
导入java.util.Set;
导入android.content.Context;
导入android.graphics.Color;
导入android.graphics.Typeface;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.BaseExpandableListAdapter;
导入android.widget.Filter;
导入android.widget.LinearLayout;
导入android.widget.TextView;
进口公司pebbo.yaa.R;
公共类CustomExpandableListAdapter扩展了BaseExpandableListAdapter{
私人语境(private Context)(私人语境);;
私有列表_listDataHeader;//头标题
//标题标题、子标题格式的子数据
私有HashMap_listDataChild;
整数[]Algs_lite={5,19};
整数[]Algs_cat_lite={1,2};
线性布局,小排,小排,儿童;
文本视图;
文本视图txtListChild;
公共CustomExpandableListAdapter(上下文、列表listDataHeader、,
HashMap listChildData){
这._context=context;
这。_listDataHeader=listDataHeader;
这。_listDataChild=listChildData;
}
@凌驾
公共对象getChild(int-groupPosition、int-ChildPosition){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition))
.get(childpositionon);
}
公共对象getChildTitle(int-groupPosition、int-ChildPosition){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition)).get(childpositionon.getName();
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition)).get(childPosition.getId();
}
public int getCatId(int groupPosition){
返回此值。_listDataHeader.get(groupPosition.getId();
}
public int-getAlgId(int-groupPosition,int-childPosition){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition)).get(childPosition.getId();
}
@凌驾
公共视图getChildView(int groupPosition,final int childPosition,
布尔值isLastChild、视图转换视图、视图组父级){
最终字符串childText=(字符串)getChildTitle(groupPosition,childPosition);
布尔存在=包含值(Algs_lite,getAlgId(groupPosition,childPosition));
if(convertView==null){
LayoutInflater INFLATER=(LayoutInflater)this.\u context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);
convertView=infalInflater.充气(R.layout.list_项,空);
ll_row_child=(LinearLayout)convertView.findViewById(R.id.ll_row_child);
txtListChild=(TextView)convertView.findViewById(R.id.lblListItem);
如果(存在){
//Log.i(“适配器1”,“值:::”+存在+::::::“+f.getId()+”::::::::::::“+f.getName()+”:::::::::::::可争议”);
ll_row_child.setBackgroundColor(颜色:白色);
setTextColor(_context.getResources().getColor(R.color.DarkBlueBG));
}否则{
//Log.e(“适配器1”,“值:::”+存在+”::::::“+f.getId()+”:::::名称::“+f.getName()+”:::::无争议”);
ll_row_child.setBackgroundColor(Color.LTGRAY);
setxtcolor(Color.GRAY);
}
}
setText(childText);
返回视图;
}
@凌驾
公共整数getChildrenCount(整数组位置){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition))
.size();
}
@凌驾
公共对象getGroup(int-groupPosition){
返回此。\u listDataHeader.get(groupPosition);
}
公共对象getGroupTitle(int groupPosition){
返回此值。_listDataHeader.get(groupPosition.getCategory();
}
@凌驾
public int getGroupCount(){
返回此值。_listDataHeader.size();
}
@凌驾
公共长getGroupId(int-groupPosition){
返回此值。_listDataHeader.get(groupPosition.getId();
}
@凌驾
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
字符串标题=(字符串)getGroupTitle(groupPosition);
boolean exists_alg=containsValue(Algs_cat_lite,getCatId(groupPosition));
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.\u上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(R.layout.list_组,空);
ll_行=(LinearLayout)convertView.findViewById(R.id.ll_行);
lblListHeader=(TextView)convertView.findViewById(R.id.lblListHeader);
如果(存在){
//Log.i(“适配器1”,“值:::”+存在+::::::“+f.getId()+”::::::::::::“+f.getName()+”:::::::::::::可争议”);
ll_row.setBackgroundColor(_context.getResources().getColor(R.color.BlueBG));
lblListHeader.setTextColor(Color.WHITE);
}否则{
//Log.e(“适配器1”,“值:::”+存在+”::::::“+f.getId()+”:::::名称::“+f.getName()+”:::::无争议”);
ll_row.setBackgroundColor(_context.getResources().getColor(R.color.DimGray));
lblListHeader.setTextColor(_context.getResources().getColor(R.color.LightGrey));
}
}
lblListHeader.setText(标题);
返回视图;
}
@凌驾
公共布尔表ID(){
返回false;
}
@凌驾
公鸡