In the Android application development process, commonly used listening events are as follows:

1. Button (button) listening event: OnClickListener interface onClick (View v) interface method;
2. SeekBar (progress bar) listening event: OnSeekBarChangedListener interface,
① onProgressChanged (SeekBar seekBar, int progress, boolean fromUser);
② onStartTrackingTouch (SeekBar seekBar ); // Slide start
③onStopTrackingTouch (SeekBar seekBar); // Slide end
3. EditText (Editor) monitoring events: OnKeyListener interface
onKey (View v, int keyCode, KeyEvent event) // Interface method to monitor keyboard events
4. RadioGroup (Radio button) monitoring event: OnCheckedChangeListener interface
5. Spinner (drop-down list) monitoring event: OnItemSelectedListener interface
① onItemSelected (AdapterView <?> Parent, View view, int position, long id);
② onNothingSelected (AdapterView <?> Parent)
6. Menu (menu) monitoring events: different internal methods of Activity call different selection methods
① public boolean onMenuItemSelected (int featureId, MenuItem item);
②public boolean onOptionsItemSelected (MenuItem item);
③public boolean onContextItemSelected (MenuItem item);
7. Dialog (dialog box) monitoring events: implement multiple general type interfaces, each of which has several interfaces, according to different types of Dialog , Will implement different interface methods. implements DialogInterface KeyEvent.Callback View.OnCreateContextMenuListener Window.Callback
such as the button type Dialog will implement the subinterface DialogInterface.OnClickListener under the general interface;
8. DatePicker (date) date change monitoring event: OnDateChangedListener interface
onDateChanged (DatePicker view, int year, int monthOfYear, int dayOfMonth);
9.DatePickerDialog event listener
onDateSetListener: trigger when the date is set
10. TimePicker (time) listener event change event of the day: OnTimeChangedListener interface
onTimeChanged (TimePicker view, int hourOfDay, int minute);
11.TimePickerDialog event Listen
onTimeSetListener: trigger when the time is set
12. SlidingDrawer (sliding drawer) monitoring events: OnDrawerOpenListener interface
onDrawerOpened (); Invoked when the drawer becomes fully open.
13. RatingBar (star rating evaluation) monitoring events: OnRatingBarChangeListener
onRatingChanged (RatingBar ratingBar, float rating, boolean fromUser );
14. Chronometer (counter) monitoring event: OnChronometerTickListener interface
onChronometerTick (Chronometer chronometer); // Prompt the counter number to change
15. ListView event monitoring
setOn ItemSelectedListener: trigger when the mouse is scrolling
setOnItemClickListener: trigger when clicking
16.Gallery event monitoring
setOnItemClickListener: Triggered when
clicked 17. GridView event listen
setOnltemClickListener: triggered when clicked

Second, the event listener and call timing defined in the View

  1. setOnClickListener(View.OnClickListener l)
  2. setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)
  3. setOnDragListener(View.OnDragListener l)
  4. setOnFocusChangeListener(View.OnFocusChangeListener l)
  5. setOnGenericMotionListener (View.OnGenericMotionListener l)
  6. setOnHoverListener(View.OnHoverListener l)
  7. setOnKeyListener(View.OnKeyListener l)
  8. setOnLongClickListener(View.OnLongClickListener l)
    9.setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener l)
  9. setOnTouchListener(View.OnTouchListener l)

Third, other types of monitoring events and interface methods
1. Animation change monitoring events
setAnimationListener (new Animation.AnimationListener () {});
①onAnimationStart (Animation animation) – called at the start of the
animation②onAnimationEnd (Animation animation) – called at the end of the animation③onAnimationRepeat
( Animation animation) – Called when the animation is repeated.
Monitor the result of a certain execution of the animation (you do n’t have to overwrite multiple methods each time)
addListener (new AnimatorListenerAdapter () {}
onAnimationEnd (Animator animation)
-only called when the animation execution is complete 2.ViewPager sliding listen for events
setOnPageChangeListener (OnPageChangeListener onPageChangeListener)
①onPageScrolled (int position, float positionOffset, int positionOffsetPixels) - when the page slide when calls this method, before the slide is stopped, this method has always been to call back; first argument: The current page, the second parameter: the current page offset percentage (with 0.6 as the boundary, whether the marker slides to the next or back to the original position), the third parameter: the current page offset Pixel location;
②onPageSelected (int position) - This method is invoked after the jump page; Parameters position as the current location;
③ onPageScrollStateChanged (int state)-called when the state changes; the parameter state has three values: 0-do nothing, 1-slide, 2-slide end;

Method of implementing event listener:

The inner class form The
outer class form
Activity itself acts as an event listener class
Anonymous inner class form
Bind directly to the label

Published 16 original articles · praised 0 · visits 852

Guess you like

Origin blog.csdn.net/weixin_45830683/article/details/103036207