3 回答
![?](http://img1.sycdn.imooc.com/545868b60001587202200220-100-100.jpg)
TA贡献1780条经验 获得超5个赞
getView
第一阶段:为循环再造而制作的物品( convertView
是 null
):这意味着创建布局和所有项共享的公共状态。如果您有侦听器,您可以在这里添加它们,并设计它们,以便它们能够在以后的位置更改(当它被重用时)作出反应。因此,例如,通过将位置设置为相应视图上的标记,监听器可以捕获该信息,并知道它当前操作的项目。不能使用视图存储数据。因此,当侦听器更改列表项上的状态时,应将此数据持久化(在数据数组中、SQLite数据库中等),并在 第二阶段.第二阶段:设置给定位置的项目状态:
设置项目的可视状态。对于某一项可能单独更改的所有内容(文本、复选框状态、颜色等)都必须在这里设置。不仅更改了当前项的内容,而且还可能被另一项更改。通过这种方式,可以确保视图不用于 无效状态,因为它以前是从另一个列表项中重用的。
getItemViewType
getViewTypeCount
getItemViewType
getViewTypeCount
void getItemViewType(int position) { return isItemAtPositionSeperator(position) ? 1 : /* normal item */ 0;}void int getViewTypeCount() { return 2; // normal item and separator}void View getView(int position, View convertView, ViewGroup parent) { int type = getItemViewType(position); // phase 1: see my explanation if (convertView == null) { if (type == 0) { // setup your common item view - inflate it and set to convertView } else { // setup separator view - inflate it and set to convertView } } // phase 2: see my explanation if (type == 0) { // set the state of the common item view based on the position // rely on the fact that convertView contains the view hierarchy // you created in convertView == null && type == 0 } else { // set state of the separator based on the position // rely on the fact that convertView contains the view hierarchy // you created in convertView == null && type != 0 (else part) } return convertView;}
问题的实际答案.。
viewHolder.checkbox.setOnCheckedChangeListener
final position
viewHolder.checkbox.setTag(position)
return
(Integer) buttonView.getTag()
position+1
viewHolder.checkbox.setChecked(persistedState)
return
.
- 3 回答
- 0 关注
- 396 浏览
添加回答
举报