In my Android application I’ve got an Activity containing an ExpandableListView.
The items it will contain should be extracted from an XML file that the application will query to a Server when it starts (suppose the size of the file is not an issue).
The user should then be able to make modifications to the content of the XML file by adding, removing, editing items from the ExpandableListView with functionalities provided by the application. Eventually the application will send back the modified XML file to the Server.
For better understanding this mockup should explain what I’m trying to implement:

I’d like to know:
how can I populate dynamically in
Javathe area highlighted in red
given theXMLfile?
SAMPLE XML FILE:
<?xml version="1.0" encoding="utf-8"?>
<Category value="Animals">
<entry>Cat</entry>
<entry>Dog</entry>
<entry>Elephant</entry>
</Category>
<Category value="Objects">
<entry>Aeroplane</entry>
<entry>Ball</entry>
<entry>Closet</entry>
</Category>
ADDED DEBUG PART
I’ve tried to implement the solution proposed in the answer by @Luksprog but am facing a java.lang.NullPointerException when running the following code:
Code:
//gets the View from the Layout file
myCustomExpandableListView = (ExpandableListView) findViewById( R.id.myCustomExpandableListView );
//creates the array list that will contain all labels
ArrayList<Category> labelsInTaxonomy = new ArrayList<Category>();
//fills it with a private method that parses the XML and fills the array list
this.loadTaxonomyFromXml( labelsInTaxonomy );
//creates the custom expandable list adapter
CustomExpandable labelTaxonomyAdapter = new CustomExpandable( this, labelsInTaxonomy );
//sets the adapter
myCustomExpandableListView.setAdapter( labelTaxonomyAdapter );
Error:
E/AndroidRuntime( 5972): FATAL EXCEPTION: main
E/AndroidRuntime( 5972): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.DVA_HLUI/com.DVA_HLUI.DVA_HLUIManageTaxonomyActivity}: java.lang.NullPointerException
E/AndroidRuntime( 5972): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
E/AndroidRuntime( 5972): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
E/AndroidRuntime( 5972): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
E/AndroidRuntime( 5972): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
E/AndroidRuntime( 5972): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5972): at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime( 5972): at android.app.ActivityThread.main(ActivityThread.java:4196)
E/AndroidRuntime( 5972): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5972): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 5972): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 5972): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 5972): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5972): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 5972): at com.DVA_HLUI.DVA_HLUIManageTaxonomyActivity.onCreate(DVA_HLUIManageTaxonomyActivity.java:80)
E/AndroidRuntime( 5972): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
E/AndroidRuntime( 5972): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
Note that
com.DVA_HLUI.DVA_HLUIManageTaxonomyActivity.onCreate(DVA_HLUIManageTaxonomyActivity.java:80)
corresponds to this line of the code
myCustomExpandableListView.setAdapter( labelTaxonomyAdapter );
Any ideas of what I’m doing wrong?
I would make a custom class like this:
as a data structure and use the
ArrayList<Category>that will result from parsing the xml in a custom adapter: