0

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"));
Thesalacium
  • 111
  • 1
  • 2
  • 7
  • see this link you can understand where is the problem http://stackoverflow.com/questions/8094268/android-listview-performitemclick – Hanuman Apr 06 '15 at 14:20

1 Answers1

1

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));
ekchang
  • 939
  • 5
  • 11