how to get id of selected item in autocompletetextview in android
Change this in adapter
@Override
public SearchFriends getItem(int index) {
return items.get(index);
}
et_search.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
SearchFriends freindPOJO= adapter
.getItem(position);
String friends_id = freindPOJO.getFriend_user_id()
}
});
Adapter you are using for et_search using
ArrayList<SearchFriends>
and you are trying to get friend_id which is string or int and you are casting it to SearchFriends which is not possible.
if you want SearchFriends object then use like this
SearchFriends object = (SearchFriends)adapter.getItem(position);
Sorry i have not check you adapter
here is the mistake you are returning string here so you cannot get SearchFriends
@Override
public String getItem(int index) {
return items.get(index).getFriend_name();
}
So i will say do this and you are good to go.
@Override
public SearchFriends getItem(int index) {
return items.get(index);
}