Мне нужен хороший способ поддерживать несколько данных уровня формы для выбора меню.
Так, например, если у меня есть
А и В, каждый может иметь 1 2 3
так
A1
A2
A3
В
B1
Би 2
B3
И это может продолжаться долго, чтобы я мог иметь A -> A1 -> A1.1 -> A1.1.1 -....
У меня есть следующий класс, работает нормально, но я подозреваю, что мы могли бы лучше.
Мне просто нужно выполнить выделение в дереве выбора, как Widget, но каждый уровень выделения представлен в другой форме (в J2ME)
import java.util.Vector;
public class Tag {
private String tag;
private Vector childTags;
private Tag parent;
Tag(String tag, Vector childtag)
{
this.tag = tag;
this.childTags= childTags;
}
public void setChildTags(Vector childTags) {
this.childTags = childTags;
}
public Vector getChildTags() {
return this.childTags;
}
public String getTag() {
return this.tag;
}
public String toString(int depth)
{
String a ="";
if(depth==0)
{
a = a + this.getTag();
}
if(this.getChildTags()!= null)
{
for(int k=0;k <this.getChildTags().capacity(); k++)
{
for (int i=0; i<depth; i++ ) {
a = a + ("-");
}
a = a+ ( ((Tag)this.getChildTags().elementAt(k)).toString(depth++));
} }
return a;
}
}