How do I clear all the EditText
fields in a layout with a Clear Button
. I have a registration Activity that has about 10 different EditTexts
. I know I could go and grab a reference to each specifically and then set.Text("")
; But I am looking for a more dynamic elegant way. Possibly grab the Layout
and loop through all the items in there looking for EditText
types and then setting those to ""
. Not sure how to do that though and tried searching on the web for it but no luck. Any sample code?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can iterate through all children in a view group and clear all the
EditText
fields:You can always do this...it works for me:
this way you have one fat button that clears all the fields for you once
Use
editText.getText().clear();
The answer by @Pixie is great but I would like to make it much better.
This method works fine only if all the EditText are in a single(one) layout but when there are bunch of nested layouts this code doesn't deal with them.
After scratching my head a while I've made following solution:
To use this method just call this in following fashion:
Where you can replace your R.id.sign_up with the id of root layout of your XML file.
I hope this would help many people as like me.
:)
use one of this code to clear your edittext
or
or
use
editText.getText().clear();
or setText as Empty using this below code
editText.setText(");