Note the point:
Must be set in front of Setcontentview, otherwise it will be error.
Important ways to:
Progress.incrementProgressBy(int diff);//参数为进度数,进度满了为100.不能够超过100.
Progress.incrementsecondaryprogressby (-10);
Package Com.wyl.progressbartest;import Android.app.activity;import Android.os.bundle;import Android.view.View; Import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.button;import Android.widget.progressbar;import Android.widget.textview;public class Mainactivity extends Activity implements Onclicklistener{button Btn01; Button btn02; TextView TV; ProgressBar pb01; ProgressBar pb02; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);/* * Enable window features, * 1. Progress bar with Progress * 2. progress bar without progress * must be set in front of Setcontentview, otherwise an error will be made. */system.out.println ("======= for Skin Health ========"); Requestwindowfeature (window.feature_progress);// Requestwindowfeature with Progress (window.feature_indeterminate_progress);//Without Progress Setcontentview (R.layout.activity_main); Init ();} /** * Initializes some controls */public void Init () {////TODO auto-generated method stub//progress = (ProgressBar) Findviewbyid (R.id.horiz );//add = (Button) Findviewbyid (r.id.add);//reduce = (Button) Findviewbyid (R.id.reduce);//reset = (Button) Findviewbyid (r.id.reset);//text = (TextView) Findviewbyid (R.id.text);//show= (Button) Findviewbyid (r.id.show);//show.setonclicklistener (this);////gets the progress of the first progress bar//int primary = progress.getprogress ();//// Gets the progress of the second progress bar//int second = progress.getsecondaryprogress ();////gets the maximum progress of the progress bar//int max = Progress.getmax ();//text.settext ( "First progress percentage:" + (int) (Primary/(FLOAT) max * 100)//+ "% second progress percentage:" + (int) (second/(float) max * +) + "%");//add.setonclic Klistener (This),//reduce.setonclicklistener (This),//reset.setonclicklistener (this);p b02 = (ProgressBar) Findviewbyid (R.ID.PROGRESSBAR2); int first = Pb02.getprogress (); System.out.println ("==first:==" +first); int second = Pb02.getsecondaryprogress (); btn01 = (Button) Findviewbyid ( R.id.button1) Btn02 = (Button) Findviewbyid (r.id.button2); TV = (TextView) Findviewbyid (R.ID.TEXTVIEW1); Btn01.setonclicklistener (this); Btn02.setonclicklistener (this);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {Case r.id.button1://increases the first progress and the second progress 10 ticks//pRogress.incrementprogressby (//progress.incrementsecondaryprogressby);p B02.incrementprogressby (-10); System.out.println ("= = = Decrease Progress 10===");p B02.incrementsecondaryprogressby ( -10); Tv.settext ("First Progress:" +pb02.getprogress ( ); Tv.settext (Tv.gettext (). toString () + ", second progress bar" +pb02.getsecondaryprogress ()); Break;case r.id.button2:// Increase the first progress and the second progress of 10 ticks//progress.incrementprogressby (10); Pb02.incrementprogressby (10); System.out.println ("= = Increase Progress 10===");p B02.incrementsecondaryprogressby, Tv.settext ("First Progress:" +pb02.getprogress ( ); Tv.settext (Tv.gettext (). toString () + ", second progress bar" +pb02.getsecondaryprogress ()); break;default:break;}}}
Android's ProgressBar