我有一个带有两个标签的活动,其中一个标签有一个带有可扩展列表视图的片段。
选择选项卡后,将调用后台操作并收集所有数据并将其设置为正确的数组。
我可以看到可扩展列表视图和相关的子视图但是当我向上和向下滚动时,我可以看到子视图的值已经改变。
base_expandable_adapter上的我正在与群组和孩子的视图持有者一起工作。我无法弄清楚的是价值观正在发生变化的原因。你有什么可以解决这个问题吗?
public class S_GRP_EXP_LST_ADAPTER extends BaseExpandableListAdapter{
private String TAG="EXP_LST_ADAPTER";
private Context CNTX;
private List<S_GRP_get_set>S_GRP_PARENT=new ArrayList<S_GRP_get_set>() ;
private HashMap<String, List<S_GRP_get_set_child>> listDataChildResult = new HashMap<String, List<S_GRP_get_set_child>>();
private ViewHolder holder=new ViewHolder();
public S_GRP_EXP_LST_ADAPTER(List<S_GRP_get_set> _S_GRP_PARENT,HashMap<String, List<S_GRP_get_set_child>> _listDataChildResult,Context _CNTX)
{
this.S_GRP_PARENT=_S_GRP_PARENT;
this.listDataChildResult=_listDataChildResult;
this.CNTX=_CNTX;
Log.i(TAG, ""+S_GRP_PARENT.size() + ""+ listDataChildResult.size());
}
@Override
public int getGroupCount() {
Log.i(TAG, "getGroupCount() invoked");
return S_GRP_PARENT.size();
}
@Override
public int getChildrenCount(int groupPosition) {
Log.i(TAG, "getChildrenCount() invoked");
return listDataChildResult.get(S_GRP_PARENT.get(groupPosition).Get_Group_Name()).size();
}
@Override
public Object getGroup(int groupPosition) {
Log.i(TAG, "getGroup() invoked");
return S_GRP_PARENT.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
Log.i(TAG, "getChild() invoked");
return listDataChildResult.get(S_GRP_PARENT.get(groupPosition).Get_Group_Name()).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
Log.i(TAG, "getGroupId() invoked");
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
Log.i(TAG, "getChildId() invoked");
return childPosition;
}
@Override
public boolean hasStableIds() {
Log.i(TAG, "hasStableIds() invoked");
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Log.i(TAG, "getGroupView() invoked");
View parentView =convertView;
LayoutInflater inflater = (LayoutInflater)this.CNTX.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
if(parentView==null)
{
parentView = inflater.inflate(R.layout.group_index_list_layout, parent, false);
holder.grp_name=(TextView)parentView.findViewById(R.id.tv_Grp_Name);
holder.grp_mtrc=(TextView)parentView.findViewById(R.id.tv_Grp_Mtrc);
holder.grp_health=(TextView)parentView.findViewById(R.id.tv_Grp_Health_Title);
parentView.setTag(holder);
}
else{
holder = (ViewHolder) parentView.getTag();
}
holder.grp_name.setText(S_GRP_PARENT.get(groupPosition).Get_Group_Name());
holder.grp_mtrc.setText(S_GRP_PARENT.get(groupPosition).Get_Group_mtrc());
holder.grp_name.setText(S_GRP_PARENT.get(groupPosition).Get_Group_Name());
return parentView;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Log.i(TAG, "getChildView() invoked");
View childView=convertView;
LayoutInflater inflaterchild = (LayoutInflater)this.CNTX.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
if(childView==null)
{
childView = inflaterchild.inflate(R.layout.group_exp_list_child_layout, parent, false);
child_holder.grp_r_index=(TextView)childView.findViewById(R.id.tv_r_S_name_in_GRP);
child_holder.grp_r_state=(TextView)childView.findViewById(R.id.tv_R_SRV_state);
childView.setTag(holder);
}
else
{
holder=(ViewHolder) childView.getTag();
}
child_holder.grp_r_index.setText(listDataChildResult.get(S_GRP_PARENT.get(groupPosition).Get_Grp_Name()).get(childPosition).get_srv_index());
child_holder.grp_r_state.setText(listDataChildResult.get(S_GRP_PARENT.get(groupPosition).Get_Grp_Name()).get(childPosition).get_srv_state());
return childView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
//class for the view holder
public class ViewHolder
{
TextView grp_name;
TextView grp_mtrc;
TextView grp_health;
TextView grp_r_index;
TextView grp_r_state;
}
}
答案 0 :(得分:1)
你好我升级后使用这个适配器进行扩展列表视图 用这个:
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;
private List<Home_property> data;
int[] images_tag;
public ExpandableListAdapter(Context context, List<Home_property> category,
int[] image) {
this._context = context;
images_tag = image;
data = category;
}
@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) {
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.setTypeface(Fontfamily.getFont(_context));
txtListChild
.setText(data.get(groupPosition).subcats.get(childPosition).subcatnam);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return data.get(groupPosition).subcats.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return data.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
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);
ImageView header = (ImageView) convertView.findViewById(R.id.header);
lblListHeader.setTypeface(Fontfamily.getFont(_context));
try {
lblListHeader.setText(data.get(groupPosition).catnam);
} catch (IndexOutOfBoundsException e) {
}
header.setBackgroundResource(images_tag[groupPosition]);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}