Skip to content Skip to sidebar Skip to footer

How To Set Focus In Listview Item?

I have to set focus on listview item. ListView consist of TextView. point where i want to set focus on listview item, at that point i have the position of that item. I have tried s

Solution 1:

I think you want to highlight a particular list item based on your requirement. So you are not able to set the focus if the item is not visible in the screen. Am I right ? If that is your problem you can use following method public void smoothScrollToPosition (int position) Added in API level 8 to scroll to that particular position and then use setSelection() method

Solution 2:

If you want to set focus/color on particular index of ListView, you should try this, it works well.

list.post(newRunnable() {
    @Overridepublicvoidrun() {
        list.setSelected(true);
        list.getChildAt(0).setBackgroundColor(Color.BLACK);
        list.getChildAt(1).setBackgroundColor(Color.BLUE);
        firstListItemPosition = firstListItemPosition +1;
        Log.v("firstListItemPosition", "firstListItemPosition ");
    }                   
});


firstListItemPosition = list.getFirstVisiblePosition();

Post a Comment for "How To Set Focus In Listview Item?"