0

我有兩個選項卡的活動,其中一個選項卡具有可擴展列表視圖的片段。當滾動展開式列表視圖textview值更改

選中該選項卡後,將調用後臺操作並收集所有數據並將其設置在適當的數組中。

我可以看到可擴展的列表視圖和相關的孩子的,但是當我上下滾動時,我可以看到,該孩子的textview的值被改變。

on the 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

,您在服務器移植ListView?如果是那樣的靜態或動態數據。因爲listview刷新滾動 – chain

+0

你能告訴我們你的代碼嗎? –

+0

嗨,流程如下:1.從設備中獲取信息2.將所有信息放入數組3.將列表適配器,傳遞列表和散列表作爲參數調用。我會在短時間內分享代碼 – user2145673

回答

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; 
    } 
} 
+0

從我看到的主要區別是你沒有使用viewholder類,你認爲這是造成這個問題的原因嗎? – user2145673

+0

好消息:-),似乎主要問題是我在兒童和小組觀點上使用的持有人。一旦我刪除他們的數據保持不變。主要問題是爲什麼持有人會創造這種行爲?他們不是想增加性能並減少內存使用嗎?你有什麼主意嗎? – user2145673

相關問題