I have create the android application program.In this program i am using the progressbar..I put the code for progressbar in the xml layout. my problem is, when i click the button after that only the progreessbar is loaded ,but it will displayed before clicking the button..pls tell some idea..Thanks in advance.开发者_运维问答.
Set android:visibility and android:id attributes for ProgressBar element.
android:visibility="gone" android:id="@+id/your_prg_bar_id"
For the button click add attribute. android:onClick
android:onClick="showProgressBar"
Inside your activity write the method showProgressBar to show progressBar.
public void showProgressBar(View source){
progressBar = (ProgressBar) findViewById(R.id.your_prg_bar_id);
progressBar.setVisibility(View.VISIBLE);
}
try this:: AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute
private class xyz extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(tranning.this);
protected void onPreExecute() {
this.dialog.setMessage("Please Wait...");
this.dialog.show();
// put your code which preload with processDialog
@Override
protected Void doInBackground(Void... arg0) {
// put your code here
return null;
}
@Override
protected void onPostExecute(final Void unused) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
}
}
and use this in your button click event ::
new xyz().execute();
精彩评论