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,,,

CodePudding user response:

reference 4 floor Xia Cheng reply:
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 ~

Finally methods with you about, implements the interface way, just have a trouble: as long as one is put on a new page controls, we must implement the interface methods, regardless of the method in any content!

CodePudding user response:

refer to 6th floor constantly surprise response:
roughly see, should be across class calls, are generally used to entrust to handle this, not professional and broadcast/eventbus method are many,,,

In c #, I were entrusted to complete this function, feel entrusted also works well

CodePudding user response:

android reference 5 floor little ape reply:
time selector ok button click event call time calculation method, each time after choosing the time calculation, then the setText into the text box

Custom controls how know the logic of the outside, don't know!

CodePudding user response:

references 9/f, adherents of power response:
Quote: refer to fifth floor android little ape reply:
time selector ok button click event call time calculation method, each time after choosing the time calculation, then the setText into the text box

Custom controls how know the logic of the outside, don't know!
show custom control interface, the external implements this interface, each click custom controls button, can call an external method

CodePudding user response:

Why custom controls, a few set inputType input box, and then add a button, not be simpler than this

CodePudding user response:

Can be done in a second time to choose click automatically calls for time and the method of ~

CodePudding user response:

11 references JMSissi response:
why custom controls, inputType under several input box set, and then add a button, can not more than the simple

With InputType is possible, but on maximum minimum constraint, make custom control has several advantages: 1, unified interface, used at many points, just put a; 2, the user can clearly know the range of maximum and minimum values, not blindly input, 3, unit of time is changing, sometimes the mm: ss is sometimes hh: mm, sometimes the mm: 10 ms, made into custom controls, I can according to the type of input value, direct display and conversion
  • Related