Select the first item by default in a Master Detail flow

有些话、适合烂在心里 提交于 2019-12-13 02:24:58

问题


I'm working on a screen for a Android app where the screen design is a Master Detail flow with a list view on the left, and a changing form on the right (similar to the wizard design in HTML)

I noticed that when the screen is first created, the right side of the screen is empty, until I manually 'click' on the first item, then it will only load the first fragment. My question is, is it possible that i load the first item by default?

I'd tried by adding the following code in the onViewCreated function in the ListFragment class . It will show the right sided screen but without the list view on the left.

getListView().requestFocusFromTouch();
getListView().setSelection(position);
getListView().performItemClick(getListView().getAdapter().getView(position, null, null), position, position);

Anyone has any idea how to do this?

Thanks.


回答1:


End up i manage to get things work by using the code below:

fragment.getListView().requestFocusFromTouch();
fragment.getListView().setSelection(position);
fragment.getListView().performItemClick(fragment.getListView().getAdapter().getView(position, null, null), position, position);



回答2:


How about writing a method to handle the ListView ItemClick event, and call this method in onCreate?



来源:https://stackoverflow.com/questions/19132007/select-the-first-item-by-default-in-a-master-detail-flow

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