回答
你可以自動完成:
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