Skip to main content

Filetree component in lwuit on android doesn't show anything?

1 reply [Last post]
bayu.utomo
Offline
Joined: 2011-10-24
Points: 0

hi guys,

I have some trouble with porting LWUIT filetree to run on android. I have successed to porting LWUIT from blackberry to android with using Ugo and Thorsten method, but when I use the Filetree component in lwuit on android, it doesn't show anything.

It seems that the trouble is in the listFilesystemRoots() method under PlatformImplementation class in com.sun.lwuit.io.impl package. But I don't know how to solve it. Anyone could give me some clue??

thanks for the advice

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bayu.utomo
Offline
Joined: 2011-10-24
Points: 0

I have solved the problem.

The problem is because of root ("/") directory on android doesn't have name, so when files[i].getName() in listFilesystemRoots method is executed to get the root name, it returns "".
So when the first time filetree showed up, it shows root folder with that blank string that returned from getName().

To solve it, I modify the getChildren method in the FileTreeModel class to get the correct string that will be showing in filetree. The code is looks like this :

public Vector getChildren(Object parent) {
Vector response = new Vector();
try {
if(parent == null) {
String[] roots = FileSystemStorage.getInstance().getRoots();
for(int iter = 0 ; iter < roots.length ; iter++) {
if(roots[iter].equals(""))
response.addElement("/");
else
response.addElement(roots[iter]);
}
} else {
String name = (String)parent;
String[] res = FileSystemStorage.getInstance().listFiles(name);
if(showFiles) {
for(int iter = 0 ; iter < res.length ; iter++) {
if(name.equals("/"))
response.addElement(name + res[iter]);
else
response.addElement(name + "/" + res[iter]);
}
} else {
for(int iter = 0 ; iter < res.length ; iter++) {
if(FileSystemStorage.getInstance().isDirectory(name + res[iter])) {
if(name.equals("/"))
response.addElement(name + res[iter]);
else
response.addElement(name + "/" + res[iter]);
}
}
}
}
} catch(Throwable err) {
err.printStackTrace();
return new Vector();
}
return response;
}

hope this will be helpfull for the others.

thanks