1
リストビューでログインをクリックすると、このツリーメニューのリストビューを作成したいと思っています。 (フラグメントのような) このような断片を使ってこれを行うには、より良い方法がありますか? 私は最初のフラグメントメニューをしたいがログイン、レポート、ログインメニュープレスで管理別のフラグメントの負荷を持っており、それはAndroidのツリーデータ構造のリストビューを作成
ユーザーIDとユーザー・ピンMainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public static void main(String[] args) {
Node treeRootNode = new Node(null);
treeRootNode.setId("Main Menu");
// add child to root node
Node child1= addChild(treeRootNode, "Login");
// add child to the child node created above
addChild(child1, "User ID");
addChild(child1, "User PIN");
// add child to root node
Node child2 = addChild(treeRootNode, "Report");
// add child to the child node created above
addChild(child2, "Shift Report");
addChild(child2,"Period Report");
Node child3 = addChild(treeRootNode, "Admin");
addChild(child3,"change PiN");
addChild(child3,"Change Role");
printTree(treeRootNode, " ");
}
private static Node addChild(Node parent, String id) {
Node node = new Node(parent);
node.setId(id);
parent.getChildren().add(node);
return node;
}
private static void printTree(Node node, String appender) {
System.out.println(appender + node.getId());
for (Node each : node.getChildren()) {
printTree(each, appender + appender);
}
}
}
Node.javaを持っています
public class Node {
private String id;
private final List<Node> children = new ArrayList<>();
private final Node parent;
public Node(Node parent) {
this.parent = parent;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<Node> getChildren() {
return children;
}
public Node getParent() {
return parent;
}
private static Node addChild(Node parent, String id) {
Node node = new Node(parent);
node.setId(id);
parent.getChildren().add(node);
return node;
}
private static void printTree(Node node, String appender) {
System.out.println(appender + node.getId());
for (Node each : node.getChildren()) {
printTree(each, appender + appender);
}
}
}
なぜすべての単語に大文字で書いていますか? – Mistalis
はい、私はすでにこれを作成し、どのようにXMLの断片と接続しますか? –
UpperCaseについて私は残念です – Elsunhoty