Code example for Handler

Methods: removeMessagessendEmptyMessage

0
 
	@Override 
	protected void drawableStateChanged() { 
		super.drawableStateChanged(); 
		int delta = isPressed()? 1 : -1;
		handler.removeMessages(-delta);
		handler.sendEmptyMessage(delta);
	} 
	 
	private Handler handler = new Handler() {
		@Override 
		public void handleMessage(Message msg) { 
			int what = msg.what; 
 
			level += what; 
			if (level >= 0 && level < transitionDrawableLength) { 
				transitionDrawable.setLevel(level); 
		        if (colors != null) { 
		        	setTextColor(colors[level]); 
		        } 
				handler.sendEmptyMessageDelayed(what, DELAY);