Hesam
Hesam

Reputation: 53600

Android, How to get single item of a row in ListView?

I have a ListView in my activity. Each row includes three TextViews in this pattern: (RowId) (Name) (Phone number)

I need to get row id when user clicks on a row. I did so many things and search the net, however i didn't find a solution. I have no idea how to get row id from following method:

listView = (ListView) findViewById(R.id.listview);
listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Log.i(TAG, "item " + position + " clicked.");

        }
});

Any suggestion would be appreciated.

Upvotes: 1

Views: 8062

Answers (3)

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

to get row element

use v.findViewById(<id of row element>);

you can use get get object data in list ...........

<your_adapter>.getItem(position);

or

parent.getItemAtPosition (position);

both will return the Object....

Upvotes: 0

ixx
ixx

Reputation: 32271

You also could use v.findViewById(R.id.yourTextViewId)

Upvotes: 9

Cata
Cata

Reputation: 11211

you could also use v.getChildAt(0) if you are sure that the ListView item is formed directly by those three TextView's

Upvotes: 0

Related Questions