Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a phone_Number from contacts ListView on onItemClicklistener

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)
}
});
like image 570
Gopal Meena Avatar asked Jun 21 '20 15:06

Gopal Meena


1 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.

like image 156
Lalit Fauzdar Avatar answered Sep 22 '22 06:09

Lalit Fauzdar