B4A Library [class] TreeView with Node class

I converted the TreeView which was shared here http://www.b4x.com/forum/basic4android-share-your-creations/8824-treeview.html#post49098 long ago, to work with Node as a class, and here is the result.
It is built with a main activity which just calls the Tree activity, wherethe scroll view is created and the management of the tree takes place.
Tree activity is creating nodes, in this example as file manager, but this can be changed easily to any other database.

Have fun !

Edit: see version 2 here http://www.b4x.com/forum/additional...lass-treeview-class-tree-node.html#post109757
 

Attachments

  • TreeView_class.zip
    21.6 KB · Views: 505
  • screen.png
    screen.png
    37.3 KB · Views: 935
Last edited:

Informatix

Expert
Licensed User
Longtime User
I get an error when I try your demo. "Program paused on line 42 / For i=0 etc." The list is not initialized.
I didn't change anything. I tested it with ICS and no SD card.

I didn't look at the code closely but it seems to me that some code could be transfered from the Tree activity to the class.
 

derez

Expert
Licensed User
Longtime User
The program looks for files in the rootexternal directory, if you don't have such (???) it will not work.

To move code to the class ? there is one tree activity and many node objects, so the logic must be the opposite approach. Please explain.
 

Informatix

Expert
Licensed User
Longtime User
The program looks for files in the rootexternal directory, if you don't have such (???) it will not work.

Hum. That means I have to debug your code to make it usable. :-(
I have a SD card in my phone, but my wife (and she's not the only one in the world) has not.

To move code to the class ? there is one tree activity and many node objects, so the logic must be the opposite approach. Please explain.

My mistake. I thought the whole tree was a class, not only the nodes. So I wondered why there's so much code in the activity. Sorry. I promise to read less quickly the next time. ;-)
 

derez

Expert
Licensed User
Longtime User
That means I have to debug your code to make it usable.

It was not meant to be usable as is, but to provide the tool (node class).

For example - by clicking a node you color it blue - what use can that be for ?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
It was not meant to be usable as is, but to provide the tool (node class).

For example - by clicking a node you color it blue - what use can that be for ?

Maybe your class is a top-notch class, maybe I need it, but I can't figure it currently. That's all I wanted to say. You know your code better than I, so I thought that solving this bug would be quicker for you than for me.
Probably, you just have to add somewhere:
If File.ExternalReadable Then
StartFolder = File.DirDefaultExternal
Else
StartFolder = File.DirInternal
End If

Anyway, thanks for sharing.
 

derez

Expert
Licensed User
Longtime User
I don't know what you need so I can't help you unless you tell me.
Both other directories that you mention do not have sub directories so it will be showing only the root node, so it is no good.

What kind of application do you need it for ?
 

derez

Expert
Licensed User
Longtime User
change lines 31-32 to be
st = "/"
rootnode.Initialize("Tree",Null,0,lw,lh,"Root:",folder,st,"plus" )
 

Informatix

Expert
Licensed User
Longtime User
I tried your class on a device with a SD card and, obviously, we have very different devices. Everything is unreadable (I see only the two first letters in portrait orientation, and only a half-line in landscape orientation).
However, it's just a design flaw. Not really important. More annoying, the click event does not seem well handled (to color the node in blue). Sometimes that works instantly (what I expect), sometimes I have to click two or three times before the node turns to blue. At first glance, I can't see why. Any idea ?

It would be nice if your demo showed a way to display nodes when they reach the right side of the screen (in a very deep tree). A horizontal scrollview ?

I tried the class also with the emulator (Android 2.2). Everything crashes quickly. Always the same line:
For i = 0 To datalist.Size - 1
But now the error is:
java.lang.StackOverflowError
 

derez

Expert
Licensed User
Longtime User
Thanks for testing and commenting.

Everything is unreadable (I see only the two first letters in portrait orientation, and only a half-line in landscape orientation).

Just change the linewidth to something larger then 40%x and you'll see it.
40%x is for landscape.

More annoying, the click event does not seem well handled (to color the node in blue). Sometimes that works instantly (what I expect), sometimes I have to click two or three times before the node turns to blue. At first glance, I can't see why. Any idea ?
No.

I tried the class also with the emulator (Android 2.2). Everything crashes quickly.
Probably trying to look where the system does not allow. I'll try to protect it.

It would be nice if your demo showed a way to display nodes when they reach the right side of the screen (in a very deep tree). A horizontal scrollview ?
I'll work on it.
 

derez

Expert
Licensed User
Longtime User
To solve the problem with clicks, change in your class:
TN.pnl.Initialize("")
by:
TN.pnl.Initialize("lbl")

OK, but how do you manage to click on the margin of 0.05%y of the panel.

Great! It's a big problem, IMHO, with treeviews on Android.

There are either vertical or horizontal scrollviews, and I'm not going to solve this issue but to modify or add something to be able to move the panel.
 

Informatix

Expert
Licensed User
Longtime User
OK, but how do you manage to click on the margin of 0.05%y of the panel.
I don't know what you mean by 0.05%y.
When you display your node, there are two bitmaps (one for the +/- icon, one for the folder/file icon), a label and lot of empty space around them and between them. That's big enough to click on. And I don't have little fingers. ;-)
You should try your code in the emulator with different OS versions and resolutions. Don't trust what you see on your device.
 

derez

Expert
Licensed User
Longtime User
OK, got you.
I already corrected it as you prposed, but I'll check the next version thoroughly before releasing it (it has a tree class and the horizontal scroll found its solution).
 
Top