I am trying to sort a list using EditText using a filter in the adapter.
The filter handles well, but the click position on the list is always constant.
i.e. The ListView gets a filter, but after selecting an item, it takes the same position as a list.
FirstScreen looks like this, and when you select Albania, Albania is displayed correctly, but when, after sorting, it selects and displays the same Albania, since the list displays 0, how to fix this problem.



Some of the code adapters are:
@Override
public Filter getFilter() {
Filter filter = new Filter() {
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
country_inf = (ArrayList<CustomCountryCodesPojo>) results.values;
notifyDataSetChanged();
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
ArrayList<CustomCountryCodesPojo> FilteredArrayNames = new ArrayList<CustomCountryCodesPojo>();
if (mOriginalNames == null) {
mOriginalNames = new ArrayList<CustomCountryCodesPojo>(
country_inf);
}
if (constraint == null || constraint.length() == 0) {
results.count = mOriginalNames.size();
results.values = mOriginalNames;
} else {
constraint = constraint.toString().toLowerCase();
for (int i = 0; i < mOriginalNames.size(); i++) {
CustomCountryCodesPojo dataNames = mOriginalNames
.get(i);
if (dataNames.countryName.toString().toLowerCase()
.contains(constraint.toString())) {
FilteredArrayNames.add(dataNames);
}
}
results.count = FilteredArrayNames.size();
results.values = FilteredArrayNames;
}
return results;
}
};
return filter;
}
My problem is that in a list item, click after some search to take it from the first position
ListView Click Code
lv_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent i = new Intent();
i.putExtra("flagId", flagId);
i.putExtra("name", allRecords.get(arg2).countryName);
setResult(RESULT_OK, (i).setAction("ok"));
finish();
}
});
source
share