我有BaseExpandableListAdapter與ExpandableListView但我有麻煩讓我的孩子ViewHolder初始化到正確的看法。我把一個破發點中getChildView並在第一時間它被稱爲一切都好BaseExpandableListAdapter與ExpandableListView返回錯誤的子視圖
groupPosition:0,childPosition:0,convertView:空
的ViewHolder獲取設置和我們是很好的第一行(0 )。下一次它被稱爲我得到:
groupPosition:0,childPosition:1,convertView:從排ViewHolder對象(0)
爲什麼返回從第0行的看法?我已經包含了我從BaseExpandableListAdapter重寫的方法。爲了獲得正確的視圖,是否還需要重寫另一種方法?
child_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="9">
<LinearLayout android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<EditText.../>
</LinearLayout>
...
</LinearLayout>
// Group and children are both collections
@Override
public int getGroupCount() {
return group.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return group.get(groupPosition).getChildren().size();
}
@Override
public Object getGroup(int groupPosition) {
return group.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return group.get(groupPosition).getChildren().toArray()[childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return getGroup(groupPosition).hashCode();
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return getChild(groupPosition, childPosition).hashCode();
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
final GroupViewHolder groupViewHolder;
if(null == convertView) {
convertView = LayoutInflater.from(context).inflate(R.layout.group_layout, parent, false);
groupViewHolder = new GroupViewHolder();
// add delete group button
} else {
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
return convertView;
}
@Override
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
final ViewHolder viewHolder;
if (null == v){
v = LayoutInflater.from(context).inflate(child_layout, parent, false);
viewHolder = new ViewHolder();
// bind edittext fields
v.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) v.getTag();
}
return v;
}
刪除您的if和else,並把這個..如果(convertView == NULL){ \t LayoutInflater infalInflater =(LayoutInflater)this._context \t .getSystemService(Context.LAYOUT_INFLATER_SERVICE); \t convertView = infalInflater.inflate(R.layout.child_layout,null); \t} – Pavya 2015-02-18 06:12:51
沒有運氣,相同的問題 – bmurmistro 2015-02-18 13:34:57