【发布时间】:2019-03-11 15:15:58
【问题描述】:
如何实用地从 textview 中的逗号分隔字符串制作按钮。
TextView ingredient_txtview = (TextView) findViewById(R.id.recipe);
String ingredients = ingredient_txtview.getText();
String[] btnArray = ingredients.split(",");
for(int i=0;i<btnArray.length;i++){
// something
}
示例:
[Textview] "Button1, Button2, Button3"
结果:
[按钮]按钮1
[按钮]按钮2
[按钮]按钮3
【问题讨论】:
-
你有字符串
"Button1, Button2, Button3"并且你想(以编程方式)创建 3 个按钮? -
质量低的问题不太可能得到正确的答复。我想念你的“你试过什么”。看看stackoverflow.com/help/how-to-ask
-
是的,字符串用逗号分隔。所以将每个单词转换为按钮。