在J2ME中维护多层次选择菜单列表的好方法
问题描述:
我需要一种很好的方法来维护多个表单层次数据以供选择菜单。 因此,例如,如果我有 A和B,每一个可能有1 2 3 所以 一个 A1 A2 A3 乙 B1 B2 B3在J2ME中维护多层次选择菜单列表的好方法
这能持续多久,让我可以有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;
}
}
答
你可以使用一些类来表示你的菜单命令。考虑1 2 3和A B C作为命令和组合方式,因此,在这里应用一些模式,可以使用Command(http://en.wikipedia.org/wiki/Command_pattern)和Composite(http://en.wikipedia.org/wiki/Composite_pattern)。让他们一起工作,它会更直接地使用和维护它,而不是一个神秘而容易出错的“childTag矢量”。
而你的问题是......究竟是什么? – 2010-03-30 11:41:14