Java Question Library Help Required for Expandable Listview

thedesolatesoul

Expert
Licensed User
Longtime User
Thanks to warwound for his demo on the listview, I managed to create an expandable listview. However, I have two problems:
a) It is not generic.
b) It is hard to use. xml layouts are required.


---------------------------------------------------------------------------------------------------------
The xml Layout Route:
---------------------------------------------------------------------------------------------------------
Now I created an adapter ExListAdapter for this.
In the getView method, the xml layout is actually inflated and the views are assigned values.
I need to find a generic way to assign the views in the layout to fields in a type.

For e.g. what I want to do:
If I have a textview in the layout called "tvChild", and I have a custom type assigned to the ChildItem in the adapter, I want to assign a value from the type to the text of tvChild.

Something like,
I have a custom type:
B4X:
Type MyType(myText as String, myInt as Int)

Dim MyChildTagObject as MyType
MyChildTagObject.myText = "The text I want to set in tvChild"
MyChildTagObject.myInt   = 5
ExListView.AddItem("MyGroupTitle","MyChildTitle",MyGroupTagObject,MyChildTagObject)
ExListView.Bind("tvChild","setText", "myText", "java.lang.String")
ExListView.Bind("progressbar1","setValue", "myInt", "java.lang.Int")

This will allow me to dynamically link the ids from the xml layout to my custom type.

I try to do it with referencing the reflection library. I can get the id of the view using getResouces, and I know the class type but I cannot cast it.
For e.g. I use a view:
B4X:
view v = context.getResource...
Reflection r = new Reflection();
r.Target = v;
r.runMethod2("setText",value,"java.lang.String");

But that does not work because the type 'view' does not have a method 'setText'. Only the TextView does. Now I do not know how to make my view a textview dynamically. I could see the class name of view, but how would I be able to declare a textview dynamically from the name?
For now I think the only way is to use an If...then...else for each view type.



---------------------------------------------------------------------------------------------------------
The other alternative: (D4A method)
---------------------------------------------------------------------------------------------------------
When I saw D4A allowing use of bal layouts in Java, I thought we could possibly do that here too.
In the getView of the adapter, instead of inflating the xml layout, I can call something like D4A.LoadLayout which also returns a view or viewgroup.
This will eliminate the need to xml layouts.
However, I still do not know how I can access the views inside that layout and assign values to it from a Type Structure.
I am sure it is possible but I do not know how.
---------------------------------------------------------------------------------------------------------

So these are my two independent questions. If I cannot find a way, then I can only hardcode the layouts and value assignments.
 
Top