在适配器中以编程方式刷新列表视图
Refresh List View programmatically within Adapter
如何刷新 子列表 Expandable List View
我正在使用以下代码删除子列表项目,但是unable to refresh
子项目列表。
public class ListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private HashMap<String, List<String>> _listDataChild;
private DBAdapter mydb;
public SyncExpandablePendingListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@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(final 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.sync_pending_list_item, null);
}
....
btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("oldList:", _listDataChild.toString());
mydb.DeleteECRecord(data2);
_listDataChild.remove(childPosition);
notifyDataSetChanged();
Log.d("newList:", _listDataChild.toString());
});
}
.............
}
实际上,我没有得到我必须做出改变的地方?我到底错过了什么? :
请让我知道我哪里做错了?我缺少什么?
在调用 notifyDataSetChanged() 之前,您必须重新加载支持适配器的列表。 notifyDataSetChanged() 使适配器知道列表已更改并因此重新加载列表。但是您必须加载适配器的后备列表才能显示视图。
您从数据库中删除了该条目,但没有将其从 HashMap 中删除。也将其从 HashMap 中删除,然后调用 notifyDataSetChanged()。
如何刷新 子列表 Expandable List View
我正在使用以下代码删除子列表项目,但是unable to refresh
子项目列表。
public class ListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private HashMap<String, List<String>> _listDataChild;
private DBAdapter mydb;
public SyncExpandablePendingListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@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(final 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.sync_pending_list_item, null);
}
....
btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("oldList:", _listDataChild.toString());
mydb.DeleteECRecord(data2);
_listDataChild.remove(childPosition);
notifyDataSetChanged();
Log.d("newList:", _listDataChild.toString());
});
}
.............
}
实际上,我没有得到我必须做出改变的地方?我到底错过了什么? :
请让我知道我哪里做错了?我缺少什么?
在调用 notifyDataSetChanged() 之前,您必须重新加载支持适配器的列表。 notifyDataSetChanged() 使适配器知道列表已更改并因此重新加载列表。但是您必须加载适配器的后备列表才能显示视图。
您从数据库中删除了该条目,但没有将其从 HashMap 中删除。也将其从 HashMap 中删除,然后调用 notifyDataSetChanged()。