回答
你可以自动完成:
ViewGroup vg= (ViewGroup) findViewById(R.id.your_layout);
int iter=0;
while(iter<vg.getChildCount()){
boolean found=false;
View rb=vg.getChildAt(iter);
if(rb instanceof RadioButton){
if(rb.getText().toString().contains(my_string)){//found a pattern
vg.removeView(rb);//remove RadioButton
found=true;
}
}
if(!found) ++iter;//iterate on the views of the group if the tested view is not a RadioButton; else continue to remove
}
上面的代码不与其他的ViewGroup内viewgroups处理(例如里面的LinearLayout另一个)。在调用removeView之后,我没有测试迭代器的代码和viewgroup的状态;你可以在控制台中检查并告诉我们。
感谢这个答案,经过一些调整,它完美的工作! – superuser
如果你把它们放在一起,像列表一样,这很简单。
为一个按钮List<RadioButton> testButtons = new ArrayList<RadioButton>();
for (RadioButton button: radioButtonList) {
if (button.getText().toString().contains("test")) {
testButtons.add(button);
}
}
// assuming that they all have the same parent view
View parentView = findViewById(R.id.parentView);
for (RadioButton testButton: testButtons) {
parentView.removeView(button)
// or as Evan B suggest, which is even simpler (though then it is not 'removed' from the view in the litteral sense
testButton.setVisibility(GONE);
}
谢谢,更新回答 – cYrixmorten
谢谢你的回答,但我最终使用了Eudhan的答案版本。 – superuser
实施例:
Button buttonOne = (Button) findViewById(R.id.buttonOne);
removeButtons();
public void removeButtons() {
if (buttonOne.getText().toString() != "test") {
buttonOne.setVisibility(GONE);
}
}
开关起来,如果你有一个数组。
您必须使用'.equals()'进行字符串比较 - 您不能使用'=='或'!='。 – kcoppock
很高兴知道!谢了哥们。 –
- 1. 测试字符串($文本),看它是否包含数字
- 2. 看看字符串是否包含子串
- 3. 的Java看看ArrayList包含字符串
- 4. 看看文件是否包含特定的字符串,然后读取该行
- 5. Java - 查看一个字符串是否包含任何字符
- 6. 查看字符串是否包含所有数字的方法
- 7. 谷歌脚本,看看文本是否包含值
- 8. Mongodb查询字符串数组,看看是否包含关键字
- 9. 检查并看看$ _POST是否包含特定的字符串PHP
- 10. Java看到列表是否包含字符串
- 11. 查看一个字符串是否包含另一个字符串
- 12. 比较字符串和数组列表,看看字符串是否包含列表中的任何内容
- 13. 查看本文字符串
- 14. 检查网页是否存在,看看它是否包含在vb.net中的字符串
- 15. 如何查看一个字符串是否包含多个不同的字母?
- 16. 测试以查看一个字符串是否只包含字母数字
- 17. 编写一个方法来查看字符串x是否包含字母“G”
- 18. 检查字符串以查看文件是否存在本地
- 19. 如何查看WebBrowser中的任何链接是否包含字符串? VB.NET
- 20. 搜索一个元素,看它是否包含一个特定的字符串
- 21. 的Ruby-on-Rails的,看看字符串包含数字,然后将其删除
- 22. 看看字符串是否开始匹配另一个字符串
- 23. PowerShell - 如何检查字符串以查看它是否包含另一个带有通配符的字符串?
- 24. 查找字符串是否包含字
- 25. 如何查询当前URL以查看它是否包含某个字符串
- 26. 检查字符串是否包含字(不是子字符串!)
- 27. 搜索字符串,看看它是否包含使用jquery的数组中的值
- 28. bat文件脚本来检查字符串是否包含其他字符串
- 29. php检查sql数据库以查看它是否包含与字符串类似的文本
- 30. PHP解析字符串,看看他们是否similiars
你如何创建这些按钮?动态或通过XML布局? –
@jeraldov我在我的xml布局文件生成它们 – superuser