我已经使用自定义过滤过程创建了编辑文本。如果我输入任何文本,列表将根据文本进行过滤。这些工作正常。我的问题是如果单击列表中的任何第二项,则隐藏列表视图。但是listview并没有隐藏。点击(第二项目列表值)始终可见。我尝试过这样的。
class Keyskilladapter extends BaseAdapter {
private List<EmpModel> movieItems;
ValueFilter valueFilter;
Context mcontext;
private List<EmpModel> mStringFilterList;
TextView designation,company;
String val;
public Keyskilladapter(Context mcontext, List<EmpModel> movieItems) {
this.mcontext = mcontext;
this.movieItems = movieItems;
this.mStringFilterList = movieItems;
this.mStringFilterList.addAll(movieItems);
}
@Override
public int getCount() {
return movieItems.size();
}
@Override
public Object getItem(int location) {
return movieItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, final ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
convertView = inflater.inflate(R.layout.job_list,parent,false);
}
designation=(TextView)convertView.findViewById(R.id.text);
final EmpModel m = movieItems.get(position);
if (m.getsearchkey_skills() != null) {
if (!m.getsearchkey_skills().equals("null")) {
designation.setText(m.getsearchkey_skills());
}
}
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
runOnUiThread(new Runnable() {
@Override
public void run() {
val = (String) (m.getsearchkey_skills()) ;
searchkey.setText(val);
key_listView.setVisibility(View.GONE);
}
});
}});
return convertView;
}
public Filter getFilter() {
if (valueFilter == null) {
valueFilter = new ValueFilter();
}
return valueFilter;
}
private class ValueFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
List<EmpModel> filterList = new ArrayList<EmpModel>();
if (constraint != null && constraint.length() > 0) {
for (int i = 0; i < mStringFilterList.size(); i++) {
if ((mStringFilterList.get(i).getsearchkey_skills().toUpperCase())
.contains(constraint.toString().toUpperCase())) {
EmpModel m = mStringFilterList.get(i);
filterList.add(m);
}
}
results.count = filterList.size();
results.values = filterList;
} else {
results.count = filterList.size();
results.values = filterList;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
movieItems = (List<EmpModel>) results.values;
notifyDataSetChanged();
}
}
public void filter(String charText) {
// charText = charText.toLowerCase(Locale.getDefault());
movieItems.clear();
if (charText.length() == 0) {
movieItems.addAll(mStringFilterList);
}
else
{
for (EmpModel wp : mStringFilterList)
{
if (wp.getsearchkey_skills().toLowerCase(Locale.getDefault()).contains(charText))
{
movieItems.add(wp);
}
}
}
notifyDataSetChanged();
}
}
searchkey.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
headline = s.toString();
adapter.getFilter().filter(s);
adapter.getFilter().filter(s, new Filter.FilterListener() {
public void onFilterComplete(int count) {
Log.d("log", "result count:" + count);
if(count==0){
}
else{
key_listView.setVisibility(View.VISIBLE);
}
}
});
}
@Override
public void afterTextChanged(Editable s) {
}
});