venkat venkat - 5 months ago 37
Android Question

How to get view from Adapter based on position and set selected as true in android?

I have a

ListView
and an
Adapter
. I want to get listItem from
adapter, and set
selected
as
true
. How to do it?
Inside the Activity, i have position, based on position i need to highlight that position row in listview.

MyActivity.java


if(drugNames.contains(selectedTCIDynamicStock)){
int indexOfDuplicate = drugNames.indexOf(selectedTCIDynamicStock);
//tried these two ways
/*way 1*/
View view1 = rowListView.getChildAt(indexOfDuplicate);
view1.setSelected(true);
/*way 2*/
View v = getViewByPosition(indexOfDuplicate,rowListView);
v.setSelected(true);
}


But i am unable to highlight ListView row based on position in activity.

Note: Here i am not touching the listview

Answer

i used this line of code... my problem is resolved

rowListView.performItemClick(rowListView.getAdapter().getView(position, null, null), position, rowListView.getItemIdAtPosition(position));
Comments