I have 5 EditTexts
in android for users to input. I would like to know if I could have a method for checking all the 5 EditTexts
if they are null. Is there any way to do this??
相关问题
- 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
To editText is empty try another this simple way :
I usually do what SBJ proposes, but the other way around. I simply find it easier to understand my code by checking for positive results instead of double negatives. You might be asking for how to check for empty EdiTexts, but what you really want to know is if it has any content and not that it is not empty.
Like so:
As SBJ I prefer to return "has no content" (or
false
) as default to avoid exceptions because I borked my content-check. That way you will be absolutely certain that atrue
has been "approved" by your checks.I also think the
if
calling it looks a bit cleaner as well:It is very much dependent on preference, but i find this easier to read. :)
"check out this i m sure you will like it."
I prefer using ButterKnife list binding and then applying actions on the list. For example, with the case of EditTexts, I have the following custom actions defined in a utility class (in this case
ButterKnifeActions
)And in the view code, I bind the EditTexts to a list and apply the actions when I need to check the views.
And of course this pattern is extendable to checking any property on any number of views. The only downside, if you can call it that, is the redundancy of views. Meaning, to use those EditTexts, you would have to bind them to single variables as well so that you can reference them by name or you would have to reference them by position in the list (
edits.get(0)
, etc.). Personally, I just bind each of them twice, once to a single variable and once to a the list and use whichever is appropriate.this function work for me
private void checkempForm() {
with this short code you can delete empty space at start and end of the string. If the string is "" return the message "error" else you ave a string