我有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