问题
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