简体   繁体   English

清除所有菜单选项<EditText>

[英]Menu option to clear all <EditText>

I am designing an app in Android Studio, but I am having trouble creating a clear option in the menu of my app.我正在 Android Studio 中设计一个应用程序,但在我的应用程序菜单中创建一个明确的选项时遇到了问题。

Can someone show me how to add a menu option that will clear all the <EditText> items in my app I am creating?有人可以告诉我如何添加一个菜单选项来清除我正在创建的应用程序中的所有<EditText>项目吗?

You can try with below code and change the id of "your_group" with your main layout id.您可以尝试使用以下代码并使用您的主要布局 ID 更改“your_group”的 ID。

ViewGroup group = (ViewGroup)findViewById(R.id.your_group);
for (int i = 0, count = group.getChildCount(); i < count; ++i) {
View view = group.getChildAt(i);
if (view instanceof EditText) {
    ((EditText)view).setText("");//here it will be clear all the EditText field
}
}

Please let me know if have any doubts.如果有任何疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM