How to hide an item in a listview in Android

后端 未结 11 1073
天涯浪人
天涯浪人 2020-12-03 07:15

I know, this question was asked before, but I haven\'t seen a working answer for it.

Is there any way to hide some items in a ListView without changing

11条回答
  •  囚心锁ツ
    2020-12-03 07:36

    In some case you have an easy solution :

    I have to hide a View in a list view because the items to populate the view are invalid, So I don't want to see the view :

    In my list adapter :

    public class PlanListAdapter extends BaseAdapter{
    
    //some code here : constructor ......
    
        // my code that create the view from the item list (one view by item ...)
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
    
            LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
            convertView = inflater.inflate(R.layout.my_layout, null);
    
            if(my_data_are_not_valid) {
                 //just create an empty view     
                 convertView = new Space(context);  
            }
            else {
                 //populate the view with data here     
                 populate(convertView);
            }
    
            return convertView;
    }
    
    //some code here to populate the view ...
    
    
    }
    

提交回复
热议问题