I want to create something like this:
That is, a menu which I can feed an arbitrarily nested tree of strings to which will then lead to an activity who has access to the selected item.
Should I create an activity class TreeSelectActivity
then pass it a List<TreeNode>
in a bundle and then recursively create a list of the next activities for each item? One activity per item doesn't seem like the correct way of doing this. Maybe it would be better if they were fragments?
What are the pros and cons of different approaches to do this, and which approach is easiest to implement?
How to use nested array in android listview? This example demonstrate about How to use a nested array in android listview. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.
Next Page. Android ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database.
By default, ArrayAdapter creates a view for each array item by calling toString () on each item and placing the contents in a TextView. Consider you have an array of strings you want to display in a ListView, initialize a new ArrayAdapter using a constructor to specify the layout for each string and the string array −
ListView Attributes Sr.No Attribute & Description 1 android:id This is the ID which uniquely ... 2 android:divider This is drawable or colo ... 3 android:dividerHeight This specifies hei ... 4 android:entries Specifies the reference ... 2 more rows ...
Look into Wizard Pager to see if this does what you need.
Otherwise, you could implement it as an activity that takes a tree and has an adapter that shows its current level, and then passes subtrees to new activities via intent extras.
Or you could implement it as a Fragment that does approximately the same thing and stay in the same activity and just do FragmentTransactions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With