小编Web*_*ine的帖子

Android ListView Adapter如何检测空列表?

我的Activity中有一个ListView,它从SimpleAdapter的扩展类中获取值.当我添加或删除其中的一些数据时,这个正常工作.

但我的问题是,当我的项目列表为空时,我想用"No item inhere"之类的消息替换listView或类似的东西.

我尝试这样做,这样:

class FavAdapter extends SimpleAdapter{
    Activity context;
    ArrayList<HashMap<String,String>> data;
    String[] items;
    int[] champs;
    int layout;

    FavAdapter(Activity _context, ArrayList<HashMap<String,String>> _data, int _layout, String[] _items, int[] _champs){
        super(_context, _data, _layout, _items, _champs );
        this.data = _data;
        this.context = _context;
        this.items = _items;
        this.layout = _layout;
        this.champs = _champs;
    }

    public View getView(int pos, View convertView, ViewGroup parent){
        //Recycling
        View row = convertView;
        //Else get from XML
        if(row == null){
            LayoutInflater infla = context.getLayoutInflater();
            row = infla.inflate(layout, null);
        } …
Run Code Online (Sandbox Code Playgroud)

android listview adapter android-arrayadapter

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

标签 统计

adapter ×1

android ×1

android-arrayadapter ×1

listview ×1