2013-09-25 33 views
0

我用我的project.I延伸BaseExpandableListAdapter擴展列表,我想唯一的標籤設置爲每一個孩子,我用下面的代碼來設置標籤:設置標籤在擴展列表每個孩子

 public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    ArrayList<String> childtemp= (ArrayList<String>) childitems.get(groupPosition); 


    final ViewHolder holder; 
    View v = convertView; 

    if (v == null) { 
     holder = new ViewHolder(); 
     v = inflatter.inflate(R.layout.childrow, null); 
     holder.text = (TextView) v.findViewById(R.id.childrow); 
     holder.checked = (CheckBox) v.findViewById(R.id.childcheck); 
     v.setTag(holder); 

     holder.checked.setChecked(false); 
     holder.checked.setTag(groupPosition*100+childPosition); 
     holder.text.setTag(groupPosition*100+childPosition); 
    } 
    else { 
     ((ViewHolder) v.getTag()).text.setTag(groupPosition*100+childPosition); 
     holder = (ViewHolder) v.getTag(); 
     getid = (Integer) holder.text.getTag(); 
     check(getid , holder); 
     } 

    holder.text.setText(childtemp.get(childPosition).toString()); 

及其工作的第一個位置,我擴大,但當我擴大另一個位置標記未設置,因爲convertView不爲空。怎麼能爲每個孩子設置標籤?我重寫onGroupExpanded但我不知道如何使用它。

回答

0
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    List<String> childtemp= (List<String>) childitems.get(groupPosition); 

    final ViewHolder holder; 
    View v = convertView; 

    if (v == null) { 
     holder = new ViewHolder(); 
     v = inflatter.inflate(R.layout.childrow, null); 
     holder.text = (TextView) v.findViewById(R.id.childrow); 
     holder.checked = (CheckBox) v.findViewById(R.id.childcheck); 
     v.setTag(holder); 

     holder.checked.setChecked(false); 
    } 
    else { 
     ((ViewHolder) v.getTag()).text.setTag(groupPosition*100+childPosition); 
     holder = (ViewHolder) v.getTag(); 
     getid = (Integer) holder.text.getTag(); 
     check(getid , holder); 
    } 

    holder.checked.setTag(groupPosition*100+childPosition); 
    holder.text.setTag(groupPosition*100+childPosition); 
    holder.text.setText(childtemp.get(childPosition).toString()); 
+0

其工作,非常感謝 – mary

相關問題