Could someone help me to create user defined listener interface with some code snippets?
相关问题
- 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
please do read observer pattern
listener interface
then in your class say
Event
classin your driver class
MyTestDriver
In the year of 2018, there's no need for listeners interfaces. You've got Android LiveData to take care of passing the desired result back to the UI components.
If I'll take Rupesh's answer and adjust it to use LiveData, it will like so:
and now in your driver class MyTestDriver:
For more information along with code samples you can read my post about it, as well as the offical docs:
When and why to use LiveData
Official docs
Create listener interface.
And create method setOnCustomClick in another activity(or fragment) , where you want to apply your custom listener......
Call this method from your First activity, and pass the listener interface...
In Android,you can create an interface such as Listener,and your Activity implements it,but i don't think it is a good idea. if we have many components to listen the changes of their state,we can create a BaseListener implements interface Listener,and use type code to handle them. we can bind the method when we create XML file,for example:
and the source code:
but i don't think it is a good idea...
Create a new file:
MyListener.java
:In your activity, implement the interface:
MyActivity.java
:In your custom class, invoke the interface when needed:
MyButton.java
:There are 4 steps:
1.create interface class (listener)
2.use interface in view 1 (define variable)
3.implements interface to view 2 (view 1 used in view 2)
4.pass interface in view 1 to view 2
Example:
Step 1: you need create interface and definde function
Step 2: use this interface in view
Step 3,4: implements to activity