Home > Mobile > Custom controls how to respond to external events?
Custom controls how to respond to external events?
Time:11-16
Do a time input custom controls:
Click the control button on the right, will pop up the selector for the user to choose and get minutes time:
Then on my UI:
Now the question is: when the user choice every time after time, I need to sum sprint and long time, if more than 5 minutes, it shows that the unqualified, show otherwise qualified,
Imagine thinking: if add a button on interface, judging by clicking on the event, is certainly no problem, but in so doing, obviously is stupid, I can see you, have no way to do this logic is in the custom controls, so how can I do it after the user selects a time can achieve this logic?
CodePudding user response:
I considered adding a interface in custom controls, adding an abstract method, interface to external to be realized, but I am a novice, haven't written a interface, don't know this line not line?
CodePudding user response:
Choose the callback time, and then call calculation method, the interface with a button, by clicking on the "event to judge" the judgment method after click choose time determine the button calls
CodePudding user response:
As a TextView setText method, can be called directly, do you have in this custom VIEW to add a method, have to do is call, not necessarily interface
CodePudding user response:
1. Assume that your control for TimeChoice 2. Set your internal controls defined interface OnTimeChoiceListener, contain methods onChoice (TimeChoice instance, String time) 3. Your external fragments/Activity implementation OnTimeChoiceListener 4. Your TimeChoice control internal contain OnTimeChoiceListener mListener; 5. When your TimeChoice complete input (this you need to know when to complete) 6. The internal method calls mListener. OnChoice (this, "xxxxTimeContent"); 7, the outside Activity/fragments according to the callback method, and through the instance parameter, you can know which one is the time, and then deal with your business logic 8. Complete, you too hard ~, android programmer too difficult ~
CodePudding user response:
Time selector ok button click event call time calculation method, each time after choosing the time calculation, and then setText to text box
CodePudding user response:
Look at roughly, it should be across class calls, are generally used to entrust to handle this, not professional and broadcast/eventbus, method are many,,,