4

I'm building my first Android app, main view and all subviews are based on a dashboard layout so I'm trying to reuse the DashboardLayout from the GoogleIO 2011.

I managed to get it working with the ViewPager using FragmentPagerAdapter (since DashboardLayout is designed as Fragment). I created three xml as DashboardLayout with 6 icons each and works perfectly.

Now it's time to make everything dynamic: I need to create DashboardLayouts programmatically according to remote data (json).

At the moment I'm calling the instantiation of the DashboardFragment in the main activity like this:

...

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 this is the 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 fragment_dashboard inflated view I think I need to Instantiate DashboardLayout and add to it buttons according to the downloaded json data. But I don't know how.

Ideas?

Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
user1170896
  • 719
  • 1
  • 7
  • 19
  • Try this link: [http://stackoverflow.com/questions/10544602/set-webview-loadurl-programmatically-that-is-in-fragment-class] – jayellos May 16 '12 at 07:29

0 Answers0