How to focus android activity to the specific item of the listview

浪子不回头ぞ 提交于 2019-12-25 05:25:07

问题


I am populating listview dynamically i want when activity is created it take the focus to the specific item of the listview. like in facebook app from notification it takes on the specific row of the comments.


回答1:


if your listview extends Activity try :

listviewName.setSelection(positionOfItem);

and if your listview extends ListActivity try :

getListView().setSelection(positionOfItem);

example for my chat application, Listview must be focused at the last row so i just put this code after message displayed

getListView().setSelection(getListAdapter().getCount()-1);



回答2:


Have you tried this:

listView.setSelection(position);


来源:https://stackoverflow.com/questions/17579305/how-to-focus-android-activity-to-the-specific-item-of-the-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!