Android Handler的递归

obtainMessage() 和 new Message() 类似;

	private boolean flag=true;
	private int x=0;
	class MyHandler extends Handler{
		@Override
		public void handleMessage(Message msg) {
			((TextView)findViewById(R.id.txt1)).setText(""+x++);
			sleep(1000);
		}
		
		public void sleep(long delayMillis){
			if(flag){
				//sendMessageDelayed(obtainMessage(0), delayMillis);	
				sendMessageDelayed(new Message(), delayMillis);
			}
		}
	}
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        //((TextView)findViewById(R.id.txt1)).setText("test2");
        MyHandler myHandler=new MyHandler();
        myHandler.sleep(1000);
        
    }


你可能感兴趣的:(Android Handler的递归)