Tap each line.
A
>
means you can go deeper into the tree.
The absence of a
>
means that the node is a leaf.
If you tap a leaf,
you go to the corresponding article in
Wikipedia,
formatted for a mobile device.
TreeActivity.java:
a
ListActivity
containing a
ListView.WikiActivity.java:
launched by the other
Activity by means of an
Intent.main.xml:
never used.AndroidManifest.xml:
uses permission
"android.permission.INTERNET"WebView
in class
WikiActivity.
Two
activity
elements,
one with the theme
"@android:style/Theme.NoTitleBar".
The underlying data structure is a tree,
recursively containing smaller trees.
When we go deeper into the tree,
we push the
Stack<Tree>.
When we come back up,
we pop the stack.
The app is smart enough not to fall off the top or bottom of the tree.
A leaf node is never pushed onto the stack.
Instead, we start a simple
Activity
that displays a Wikipedia article.
There was so much data that I should have put it in a separate object, called a model (as in Model-View-Controller).
At any given time, the
ListView
is displaying a non-empty list of items.
(An empty list [i.e., a leaf] would be displayed as a Wikipedia article.)
Each non-empty list comes from a
MyAdapter.
The two most important methods of the
MyAdapter
are
getCount
and
getView.
Each view is a
horizontal
LinearLayout
containing two
TextViews,
a left-justified name
and a (possibly invisible) right-justified
>.
To give the the views the standard appearance,
they are inflated from the
TextView
in
android-sdks/platforms/android-14/data/res/layout/simple_list_item_1.xml.
.xml
file.
See
TypedArray.