1.自动增加进度:用到JAVA进程的知识
(1)布局一个Button:
(2)定义对应的java程序:
(3)java程序中定义监听事件:
(4)多线程处理和定义监听器:
Handler BarHandler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); } }; //实现一个子线程,在子线程中休眠并自动激活 Runnable updateThread=new Runnable() { int i=0; @Override public void run() { Message msg=BarHandler.obtainMessage(); msg.arg1=i; i=i+2; try{ Thread.sleep(1000); }catch(InterruptedException e){ e.printStackTrace(); } BarHandler.sendMessage(msg); if(i==100){ BarHandler.removeCallbacks(updateThread); } } }; class autoListener implements View.OnClickListener{ @Override public void onClick(View view) { progressBar.setVisibility(View.VISIBLE); BarHandler.post(updateThread); } }