Listview Setonitemclicklistener Not Working After Implementing Search
I have a simple listview inside a dialog which has a search function. The search function is working fine, but the list's setOnItemClickListener stops working after a search is per
Solution 1:
Try this way to implement clickListener
publicclassCustomDialogAdapterBasicextendsArrayAdapter<String> implementsFilterable {
Context context;
List<String> valuesComingIn = newArrayList<String>();
List<String> valuesFiltered = newArrayList<String>();
privateItemFiltermFilter=newItemFilter();
publicCustomDialogAdapterBasic(Context context, int resource, List<String> listComingIn) {
super(context, resource);
this.context = context;
this.valuesComingIn = listComingIn;
this.valuesFiltered = listComingIn;
}
publicvoidupdateBrowser() {
this.notifyDataSetChanged();
}
@OverridepublicintgetCount() {
return valuesFiltered.size();
}
public String getItem(int position)throws IndexOutOfBoundsException {
return valuesFiltered.get(position);
}
publiclonggetItemId(int position) {
return position;
}
@OverridepublicbooleanisEnabled(int position) {
returntrue;
}
@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
LayoutInflaterinflater= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewrowView= inflater.inflate(R.layout.qustom_layout_list, parent, false);
TextViewtextView= (TextView) rowView.findViewById(R.id.basic_text_view);
textView.setTypeface(TypeFaceController.generalTextFace(context));
textView.setText(getItem(position));
textView.setOnClickListener(newListener(getItem(position)));
return rowView;
}
public Filter getFilter() {
return mFilter;
}
classListenerimplementsView.OnClickListener
{
String textData;
Listener(String textData)
{
this.textData = textData;
}
@OverridepublicvoidonClick(View v) {
// Implement your click functionality here and call any method of activity like this// ((ActivityName)context).methodName();
}
}
privateclassItemFilterextendsFilter {
@Overrideprotected FilterResults performFiltering(CharSequence constraint) {
StringfilterString= constraint.toString().toLowerCase();
Log.e("filterString", filterString);
FilterResultsresults=newFilterResults();
final List<String> list = valuesComingIn;
intcount= list.size();
final ArrayList<String> nlist = newArrayList<String>(count);
String filterableString ;
for (inti=0; i < count; i++) {
filterableString = list.get(i);
if (filterableString.toLowerCase().contains(filterString)) {
nlist.add(filterableString);
}
}
results.values = nlist;
results.count = nlist.size();
return results;
}
@SuppressWarnings("unchecked")@OverrideprotectedvoidpublishResults(CharSequence constraint, FilterResults results) {
valuesFiltered = (ArrayList<String>) results.values;
notifyDataSetChanged();
}
}
}
Solution 2:
Try adding
android:descendantFocusability="blocksDescendants"
in the parent layout of XML.
Post a Comment for "Listview Setonitemclicklistener Not Working After Implementing Search"