How to get a phone_Number from contacts ListView on onItemClicklistener

Viewed 185

I have created a List of Contacts that's working but when I click on any contact I only get contact Number of 1st Item on the android screen from the ListView.

I want to get Phone Number of clicked contact of that position. I have searched on web everywhere but didn't get any solution, i am trying to solve this issue for last 13 days but still i am unable to solve this, If anyone can resolve this issue please answer. Thanks for your help brother/sister!


li.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

TextView txtNummber = li.findViewById(android.R.id.text2)
}
});
2 Answers

In your onItemClick(), you're using li.findViewById().

But, onItemClick() returns View as an argument of the clicked item, which is also mentioned in the official documentation.

Hence, try updating it as

TextView txtNummber = view.findViewById(android.R.id.text2).

Check if it works.

You can use this Contact Lib for any kind of filters. I would recommend you to use Recyclerview instead of ListView. To implement search in RecyclerView check this out.

Recylerview performance is better than Listview. Let me know If you have any issue in the implementation.

Related