我有一个扩展ParseQueryAdapter
的适配器。我想删除函数getItemView()
中的一个项目,所以我打电话给:
public View getItemView(final AlertObject alertObject, View view, final ViewGroup parent) {
... // Some conditions
alertObject.deleteInBackground(new DeleteCallback() {
@Override
public void done(ParseException e) {
if(e == null) {
notifyDataSetChanged();
} else {
LogUtils.e(LogUtils.getTag(), e.getMessage());
}
}
});
...
}
但是,删除项目后ListView
不会刷新。我做错了什么?
修改
Adapter和ListView之间的映射完成如下:
ParseQueryAdapter.QueryFactory<AlertObject> factory =
new ParseQueryAdapter.QueryFactory<AlertObject>() {
public ParseQuery<AlertObject> create() {
ParseQuery<AlertObject> query = AlertObject.getQuery();
query.orderByDescending(AlertObject.TIMESTAMP_KEY);
query.fromLocalDatastore();
return query;
}
};
alertsListAdapter = new AlertListItemAdapter(activity, factory);
alertsListView = (ListView) rootView.findViewById(R.id.alerts_list_view);
alertsListView.setAdapter(alertsListAdapter);
替代解决方案
目前我正在使用替代解决方案,即在删除后刷新片段:
((MainActivity)context).getFragmentManager().beginTransaction()
.detach(listAlertsFragment)
.attach(listAlertsFragment)
.commit();