我使用列表适配器和地图值作为数据.当我使用adapter.notifyDataSetChanged();列表中的数据不更新时.但是,如果我用ArrayList替换Map,一切正常.以下是我的适配器代码.
public class CategoryAdapter extends BaseAdapter {
ArrayList<Category> list = new ArrayList<Category>();
Context context;
public CategoryAdapter(Context context, Map<String, Category> categories) {
this.context = context;
list.clear();
list.addAll(categories.values());
}
@Override
public int getCount() {
return list.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHandler handler;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.category_list_item, null);
handler = new ViewHandler();
handler.name = (TextView) convertView.findViewById(R.id.name);
handler.count = (TextView) convertView.findViewById(R.id.count);
convertView.setTag(handler);
} else …Run Code Online (Sandbox Code Playgroud)