Android Custom Event Listener

前端 未结 3 2044
无人共我
无人共我 2020-11-28 02:24

Say I want to make my own event listener for my class, how do I do that? Do I need to maintain a thread manually?

3条回答
  •  囚心锁ツ
    2020-11-28 03:07

    I found this tutorial to be VERY HELPFUL. It explains the four steps to using a custom listener to manage callbacks in your code:

    1.Define an interface as an event contract with methods that define events and arguments which are relevant event data.

    2.Setup a listener member variable and setter in the child object which can be assigned an implementation of the interface.

    3.Owner passes in a listener which implements the interface and handles the events from the child object.

    4.Trigger events on the defined listener when the object wants to communicate events to it's owner

    Hope it helps!

提交回复
热议问题