开发者

How to dismiss the Progress Bar?

开发者 https://www.devze.com 2023-01-10 01:29 出处:网络
I\'m new to android now I\'m developing an application where a file is downloaded. I w开发者_StackOverflow社区ant to show a progressbar while the file is being download.i don\'t know where to check th

I'm new to android now I'm developing an application where a file is downloaded. I w开发者_StackOverflow社区ant to show a progressbar while the file is being download.i don't know where to check the condition for showing the Progress Bar and also i don't know how to dismiss the Progress Bar.


Just Set setVisibility GONE

if(progressBar.getVisibility() == View.VISIBLE)
{
   progressBar.setVisibility(View.GONE);
}


Lot's of people have confusion on ProgressBar and ProgressDialog.

ProgressBar is a view in layout and ProgressDialog is class.

To enable, disable, dismiss progressbar we need to use:

progressBar.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.GONE);

and to dismiss progressdialog we need to write:

dialog.dismiss();


That's done with the help of AsyncTask (an intelligent backround thread) and ProgressDialog

When the AsyncTask starts we raise a progressdialog with indeterminate state, once the task is finished we dismiss the dialog.

Example code
What the adapter does in this example is not important, more important to understand that you need to use AsyncTask to display a dialog for the progress.

private class PrepareAdapter1 extends AsyncTask<Void,Void,ContactsListCursorAdapter > {
    ProgressDialog dialog;
    @Override
    protected void onPreExecute() {
        dialog = new ProgressDialog(viewContacts.this);
        dialog.setMessage(getString(R.string.please_wait_while_loading));
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.show();
    }
    /* (non-Javadoc)
     * @see android.os.AsyncTask#doInBackground(Params[])
     */
    @Override
    protected ContactsListCursorAdapter doInBackground(Void... params) {
        cur1 = objItem.getContacts();
        startManagingCursor(cur1);

        adapter1 = new ContactsListCursorAdapter (viewContacts.this,
                R.layout.contact_for_listitem, cur1, new String[] {}, new int[] {});

        return adapter1;
    }

    protected void onPostExecute(ContactsListCursorAdapter result) {
        list.setAdapter(result);
        dialog.dismiss();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消