In this post we are going to add a ListFragment backed by the RoboSpice data from the first post
The git repo is here.
Firstly, we are going to need to bump the sdk version to 11
AndroidManifest.xml. We could use the support version
of the Fragment api, but in this instance we don’t need to.
Then we’ll create a RedditListFragment by extending ListFragment:
Notably, we have it set to log out the position of taps to LogCat and we set a new adapter (with empty content) for the ListView.
We also need an item layout to display our data. We use a
LinearLayout with vertical alignment and some
sensible margins to arrange our three
TextViews. We set
some stylistic effects (color, bold/italics) on our
TextViews to make the display a little nicer.
Of note is the
android:id fields. We will use these in our
adapter to identify each
Next we need to extend an adapter to map the data we get
from RoboSpice to the
Notably, we are using the ViewHolder pattern for performance
child.getData() to get at each
Add a RedditListFragment to the view using FragmentManager:
Then in our Request Listener add the data to the ListFragment Adapter:
At this point we’re good to go. Fire up the app and you should see something similar to this: