Used Lazy Adapter in android to getFilter for not removing rows

516 Views Asked by At

I am using a LazyAdapter(android) to populate a list but now I am trying to add a search functionality to it. I have created the following getFilter function that works only partially...

 public View getFilter(CharSequence seq, View convertView) {

        String locationName;
        View vi = convertView;
        convertView = null;
        if (convertView == null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView name = (TextView)vi.findViewById(R.id.name); // title
        TextView smallDesc = (TextView)vi.findViewById(R.id.smallDesc);
        TextView address = (TextView)vi.findViewById(R.id.address);
        TextView phone = (TextView)vi.findViewById(R.id.phone);// artist name
        TextView latitude = (TextView)vi.findViewById(R.id.latitude);
        TextView longitude = (TextView)vi.findViewById(R.id.longitude);
        TextView thumb_url = (TextView)vi.findViewById(R.id.thumb_url);
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

        for (int i = 0; i < data.size(); i++) {
            HashMap<String, String> locationList = new HashMap<String, String>();
            locationList = data.get(i);
            locationName = locationList.get(CustomizedListView.KEY_NAME);

            if (locationName != null && seq != null) {
                if (locationName.contains(seq)) {
                    name.setText(locationList.get(CustomizedListView.KEY_NAME));
                    address.setText(locationList.get(CustomizedListView.KEY_ADDRESS));
                    phone.setText(locationList.get(CustomizedListView.KEY_PHONE));
                    smallDesc.setText(locationList.get(CustomizedListView.KEY_SMALLDESC));
                    latitude.setText(locationList.get(CustomizedListView.KEY_LATITUDE));
                    longitude.setText(locationList.get(CustomizedListView.KEY_LONGITUDE));
                    thumb_url.setText(locationList.get(CustomizedListView.KEY_THUMB_URL));

                    String picture_name = (String) thumb_url.getText();
                    String _path = Environment.getExternalStorageDirectory().getAbsolutePath();
                    String location = _path+picture_name;
                    Bitmap bMap = BitmapFactory.decodeFile(location);
                    thumb_image.setImageBitmap(bMap);

                    notifyDataSetChanged();
                } else {
                    locationList.remove(CustomizedListView.KEY_NAME);
                    locationList.remove(CustomizedListView.KEY_ADDRESS);
                    locationList.remove(CustomizedListView.KEY_PHONE);
                    locationList.remove(CustomizedListView.KEY_SMALLDESC);
                    locationList.remove(CustomizedListView.KEY_LATITUDE);
                    locationList.remove(CustomizedListView.KEY_LONGITUDE);
                    locationList.remove(CustomizedListView.KEY_THUMB_URL);
                }
            }
        }
        return vi;
    }`

The filter is working but instead of removing the entire row, it is just removing the labels of that row and I can still click on it.

How can I set it to remove the entire row if the string that I am searching is not list?

0

There are 0 best solutions below