我正在使用LazyAdapter(android)来填充列表,但现在我正在尝试为其添加搜索功能。我创建了以下仅部分工作的getFilter函数...
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;
}`
过滤器正在运行,但它不是删除整行,而是删除该行的标签,我仍然可以点击它。
如果我搜索的字符串不是列表,如何将其设置为删除整行?