【发布时间】:2015-01-07 11:29:16
【问题描述】:
我有一个包含两个选项卡的活动,其中一个选项卡有一个带有可展开列表视图的片段。
选择选项卡时,正在调用后台操作并收集所有数据并将其设置为适当的数组。
我可以看到可展开的列表视图和相关的子视图,但是当我上下滚动时,我可以看到子文本视图的值发生了变化。
在 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;
}
}
【问题讨论】:
-
您是从服务器填充列表视图吗?如果是,那是静态数据还是动态数据。因为列表视图在滚动时得到了刷新
-
你能告诉我们你的代码吗?
-
您好,流程如下:1.从设备获取信息 2.将所有信息放入数组中 3.调用列表适配器并将列表和哈希图作为参数传递。稍后我将分享代码
-
使用这个stackoverflow.com/questions/10497559/… ..我的问题已经解决了......我面临同样的问题
标签: android expandablelistview expandablelistadapter android-recyclerview