I have an activity with 20 EditTexts
on it. I want to display a message if anything has been entered. Instead of attaching 20 listeners to each field, is there a way to know if input has been supplied(data changed)?
相关问题
- 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
Have your TextViews all call the addTextChangedListener() giving them your Activity as an argument (this). Have your Activity implement TextWatcher and override afterTextChanged(). Whenever one of the TextView changes, afterTextChanged() will be called. Here is an idea of what your code should look like
Here is an example of a base class that takes care of notifying subclasses if any of their
EditText
widgets is being used(if any exist). Depending on what you want to do when the user inputs something you may need to change my example to suit your particular case.Base activity from which you'll inherit:
Then all you have to do in your activities is implement the
onInputchange
callback to let you know that the user entered something in one of theEditTexts
from the current layout. You may want to look at the key event callbacks from the activity class for something simpler, but if I'm not mistaken those events are consumed by theTextView
/EditText
widgets.