
void genNav(String path1) {
linearLayout_nav.removeAllViews();
String[] SL = path1.split("/");
for (int i=0; i<SL.length; i++) {
Button button = new Button(this);
if (i == 0)
button.setText("/");
else
button.setText(SL[i]);
button.setBackground(null);
linearLayout_nav.addView(button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ViewGroup parent = (ViewGroup) view.getParent();
int index = parent.indexOfChild(view);
String path2 = "";
for (int i=0; i<parent.getChildCount(); i++) {
View child = parent.getChildAt(i);
if (child instanceof Button) {
Button button1 = (Button) child;
String SB = button1.getText().toString();
if (SB.equals("/"))
path2 = "/";
else
if (path2.equals("/"))
path2 += SB;
else
path2 += "/" + SB;
}
if (i == index)
break;
}
path = path2;
genList(path);
}
});
if (i<SL.length - 1) {
TextView textView = new TextView(this);
textView.setText(">");
linearLayout_nav.addView(textView);
}
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.scrollTo(linearLayout_nav.getMeasuredWidth(), 0); //滚到最右边
}
});
}
}