Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 自定义POJO的筛选列表视图';在他们的田地旁_Java_Android_Listview_Filtering - Fatal编程技术网

Java 自定义POJO的筛选列表视图';在他们的田地旁

Java 自定义POJO的筛选列表视图';在他们的田地旁,java,android,listview,filtering,Java,Android,Listview,Filtering,我有一个POJO: public class RoomData implements Parcelable { private String objectId, name, building, floor, imageUrl; private boolean hasPc, hasProjector, hasTelepresence, hasWhiteboard; private boolean dataReady = false; private ArrayLis

我有一个POJO:

public class RoomData implements Parcelable {
    private String objectId, name, building, floor, imageUrl;
    private boolean hasPc, hasProjector, hasTelepresence, hasWhiteboard;
    private boolean dataReady = false;
    private ArrayList<MeetingData> meetingData = new ArrayList<MeetingData>();
    private int capacity;
    private ArrayList<BeaconData> beacons = new ArrayList<BeaconData>();
    private DateTime nextAvailableStart, nextAvailableEnd;
    private boolean availableNow = false;
    private ArrayList<Interval> meetingDuringIntervals = new ArrayList<Interval>();
}

在OP的要求下,我将我的评论作为回答,以备将来参考,并提供更多细节。以下是一些可能的解决方案:

  • 破坏性更新:循环浏览列表,过滤掉你不需要的内容。基于此列表实现适配器

  • 虚拟视图:在原始列表上实现“虚拟视图”的逻辑。在这里,您只保留原始列表,但在所有适配器的方法中,您都会跳过与筛选器不匹配的项。例如,在
    getItem(int-pos)
    中,您在列表中循环保存一个计数器,但只有当该项与过滤器匹配时,您才增加它:当计数器等于pos时,您返回该项。其他方法也类似

  • 具体视图:使用附加列表将“视图”保留在原始列表上,以便缓存在2中完成的计算。当设置/更新过滤器时,通过原始列表的循环构建“视图”,然后根据“视图”实现适配器。时间效率更高,但占用的内存也更多


  • 只需在列表中循环筛选出你不需要的内容。或者,如果需要更改过滤器,可以保留一个新列表,该列表是整个列表的视图。然后在AdapterID中的整个列表上使用视图。很好。发布它,我将接受它作为解决方案。谢谢@Gil
    public class BeaconAdapter extends BaseAdapter {
        private Context context;
        private ArrayList<BLEDeviceAdvertisement> beaconArrayList = new ArrayList<BLEDeviceAdvertisement>();
    
        private static LayoutInflater inflater = null;
    
        //BeaconAdapter for the custom ListView
        public BeaconAdapter(Context context, ArrayList<BLEDeviceAdvertisement> beaconArrayList) {
            this.beaconArrayList = beaconArrayList;
            this.context = context;
            inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
    
        @Override
        public int getCount() {
            return beaconArrayList.size();
        }
    
        @Override
        public BLEDeviceAdvertisement getItem(int position) {
            return beaconArrayList.get(position);
        }
    
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        //Custom getview for the custom layout beacon_row_item.
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View myCustomView = convertView;
    
            if (myCustomView == null)
                myCustomView = inflater.inflate(R.layout.beacon_row_item, null);
    
            return myCustomView;
        }
    
    }