I am creating my first Android application, the main view and all the subheadings are based on the toolbar layout, so I am trying to reuse DashboardLayout from GoogleIO 2011.
I managed to get it to work with ViewPager using the FragmentPagerAdapter (since the DashboardLayout created as a fragment). I created three xml as a DashboardLayout with 6 icons each and it works fine.
Now it's time to make everything dynamic: I need to create the DashboardLayout program code according to the deleted data (json).
At the moment, I am calling the DashboardFragment instance in the main view:
... ArrayList<Fragment> fragments = new ArrayList<Fragment>(); fragments.add(Fragment.instantiate(this, DashboardFragment.class.getName())); ...
in the DashboardFragment class I have:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_dashboard, container, false); }
and basically it is a fragment_dashboard XML file:
<com.google.android.ui.widget.DashboardLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/firstbutton" style="@style/DashboardButton" android:text="@string/btn_first" android:drawableTop="@drawable/btn_first" /> ... </com.google.android.widget.DashboardLayout>
Now, instead of returning the bloated view of the part_dashboard fragment, it seems to me that I need to activate the DashboardLayout and add buttons to it according to the loaded json data. But I dont know how.
Ideas?
source share