set focus on any item of listview in android

前端 未结 5 1531
时光取名叫无心
时光取名叫无心 2021-01-02 09:33

I have a listview which contains textviews as its elements.

  1. Now I want the first item of the list to be automatically focused when I launch the application
5条回答
  •  借酒劲吻你
    2021-01-02 10:12

    Setting selection and setting focus are two different things. If you want to just setSelection to some item then you can use below code.

        mListView.setSelection(position);
    

    But this definitely does not mean the Listview is focused.For focussing you have to use

        mListView.requestFocus();
    

    For changing focus on click of a button you can place the code on onClick() of the button.

提交回复
热议问题