How to implement a nested master detail flow on Android? -
i have list, within list, within list, , on. there's 5 tiers.
it's easy enough create 5 activities each list on phones, if want support tablets well? i'd need work master detail flow.
however, can't seem find tutorials or information in relations nested master detail flow.
anyway, here illustration of i'm describing:
in tablet layout, want screen shift 2 tiers @ time. user can advanced next tier selecting list item right tier. go previous tier, user can tap button.
any idea how can achieve this?
after full day scouring internet, found solution. "nested master details flow" effect use viewpager fragmentpageadapter. master detail flow this:
to change 2 panel mode when user switches landscape, in extended fragmentpageradapter class, override following method:
@override public float getpagewidth(int position) { displaymetrics metrics = getresources().getdisplaymetrics(); // if width greater 900dp halve width of page if ((metrics.widthpixels / metrics.density) > 900) { return (0.5f); } return super.getpagewidth(position); }
to provide "up button" view pager:
viewpager.addonpagechangelistener(new viewpager.onpagechangelistener() { // method invoked when new page becomes selected. @override public void onpageselected(int position) { if (position == 0) { getsupportactionbar().setdisplayhomeasupenabled(false); } else { getsupportactionbar().setdisplayhomeasupenabled(true); } } });
you can tell "up button" go page (where viewpager member variable of activity, holding reference viewpager):
@override public boolean onoptionsitemselected(menuitem item) { int position = viewpager.getcurrentitem(); if (position > 0) viewpager.setcurrentitem(position-1); return true; }
references:
viewpager fragmentpageradapter
multiple-view viewpager options
how implement viewpager different fragments / layouts , example github project
Comments
Post a Comment