I am trying to sort the list by EditText using filter in adapter.
Filter is processing well but the position of listview click is always constant.
i.e. ListView is getting filter but after selection of item its taking the same position in the list view.
FirstScreen looks like this and when when the albania is selected albania is displayed properly but when after sorting behrain get selected and same albania is displayed since poition is 0 in the list view how to rectify this issue
Some of the code in adapter is :
@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();
// System.out.println(results.count);
results.values = FilteredArrayNames;
// Log.e("VALUES", results.values.toString());
}
return results;
}
};
return filter;
}
My problem is that in list item click after some search its taking from the first position
ListView click code is
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();
}
});
i.putExtra("flagId", flagId); i.putExtra("name", allRecords.get(arg2).countryName);
. Right? – Vannessavanni