Thesalacium
Thesalacium

Reputation: 111

Android ListView performitemclick (not position)

How can I change the code below?

this is actually:

lv.performItemClick(lv, 1, lv.getItemIdAtPosition(1));

I want this

lv.performItemClick(lv, "lorem ipsum", lv.getItemIdAt**Position**("lorem ipsum"));

Upvotes: 0

Views: 243

Answers (1)

ekchang
ekchang

Reputation: 939

If you are using an ArrayAdapter you can grab the adapter and use getPosition. Also the View parameter refers to the child view within the ListView, not the ListView itself.

ArrayAdapter<String> adapter = (ArrayAdapter<String>) lv.getAdapter();
int position = adapter.getPosition("lorem ipsum");

lv.performItemClick(lv.getChildAt(position), position, lv.getItemIdAt(position));

Upvotes: 1

Related Questions