Use of ProgressBar in Android

Source: Internet
Author: User

Tutorials for Beginners:

1. The main thread receives the download complete message
Private Handler Mhandler = new Handler (new Handler.callback () {
@Override
public boolean handlemessage (message message) {
Mprogressbar.setmax (100);//Set maximum
Mprogressbar.setprogress (counter);//Progress value
return false;
}
});
2.layoutinflater.from Layout Manager

/*
From a context, get a layout filler so you can use this shim to convert the XML layout file to a View object.
Load Layout Manager
Layoutinflater Inflater = layoutinflater.from (context);
To convert an XML layout to a View object
Convertview = Inflater.inflate (r.layout.item_myseallist,parent, false);
Use the View object to find the components in the layout
Convertview.findviewbyid (R.id.delete);
*/
Mprogressbar = (ProgressBar) layoutinflater.from (this). Inflate (R.layout.process,null);
3.view settings.
Setprogressbar
Mstreetview.setprogressbar (Mprogressbar);
4. Sub-thread download, send message
  Child threads
private void StartProcess () {

New Thread () {
public static final int MSG = 1;
@Override
public void Run () {

if (counter< max) {
Counter + = 10;//increased by 10 at a time

Message msg = new Message ();
Msg.what = MSG;
Mhandler.sendmessage (msg);
}
}
};
}
5. Set the progress bar to color, and so on.
The following is all the code:
public class StreetView extends Activity implements view.onclicklistener{
Private Com.leador.streetview.truevision.StreetView Mstreetview,mstreetview1;
Private TextView Tv_title;
Private LinearLayout Ll_back;
Private ProgressBar Mprogressbar;
int counter=0;

Private Handler Mhandler = new Handler (new Handler.callback () {
@Override
public boolean handlemessage (message message) {
Mprogressbar.setmax (100);//Set maximum
Mprogressbar.setprogress (counter);//Progress value
return false;
}
});


@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Requestwindowfeature (Window.feature_no_title);
Setcontentview (R.layout.activity_street_view);

/*
/From a context, get a layout filler so you can use this shim to convert the XML layout file to a View object.

Load Layout Manager
Layoutinflater Inflater = layoutinflater.from (context);
To convert an XML layout to a View object
Convertview = Inflater.inflate (r.layout.item_myseallist,parent, false);
Use the View object to find the components in the layout
Convertview.findviewbyid (R.id.delete);
*/
Mprogressbar = (ProgressBar) layoutinflater.from (this). Inflate (R.layout.process,null);

Tv_title = (TextView) Findviewbyid (r.id.tv_top);
Ll_back = (linearlayout) Findviewbyid (r.id.ll_back);
Mstreetview = (Com.leador.streetview.truevision.StreetView) Findviewbyid (R.ID.GL);
MStreetView1 = (Com.leador.streetview.truevision.StreetView) Findviewbyid (R.ID.GL1);

Init ();
Loadstreetview ();
StartProcess ();
}

private void init () {
Tv_title.settext ("Woququququuq");

Mstreetview.setprogressbar (Mprogressbar);
Mstreetview1.setprogressbar (Mprogressbar);

Ll_back.setonclicklistener (this);
}

Child threads
private void StartProcess () {

New Thread () {
public static final int MSG = 1;
@Override
public void Run () {

if (counter< max) {
Counter + = 10;//increased by 10 at a time

Message msg = new Message ();
Msg.what = MSG;
Mhandler.sendmessage (msg);
}
}
};
}

private void Loadstreetview () {
Mstreetview.setstreetviewfirstloadlistener (New Streetviewfirstloadlistener () {
@Override
public void Firstload () {
Mstreetview.loadstreetviewbyposition (110.4010705,19.977281293);
}
});

Mstreetview1.setstreetviewfirstloadlistener (New Streetviewfirstloadlistener () {
@Override
public void Firstload () {
Mstreetview1.loadstreetviewbyposition (110.4010705,19.977281293);
}
});
}

@Override
public void OnClick (view view) {
Switch (View.getid ()) {
Case R.id.ll_back:
Finish ();
Break
}
}

@Override
protected void OnDestroy () {
Super.ondestroy ();
Mstreetview.finish ();
}
}

--------------------------------------------------------------------------------------------------------------- ----------------------
--
vv
--






Use of ProgressBar in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.