小编Kri*_*906的帖子

在使用数据作为Map的notifyDataSetChanged之后,Android ListView不会刷新

我使用列表适配器和地图值作为数据.当我使用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)

android listview baseadapter

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

baseadapter ×1

listview ×1