开发者

how to use progressbar without using thread and handler?

How to use Progressbar without using thread and handler? i used following code but this is not working.

ProgressDialog prd=new Prog开发者_StackOverflowressDialog(this);
prd.setTitle("Please Wait........");
prd.show();


private class SomeTask extends AsyncTask {
private ProgressDialog dialog = new ProgressDialog(SomeActivity.this);

@Override
protected void onPreExecute() {
    this.dialog.setMessage(getResources().getString(R.string.someMessage));
    this.dialog.show();
}


@Override
protected List<Object> doInBackground(Object... objects) {
                ....
                try {
                // some logic here
            } catch (Exception e) {
                e.printStackTrace();
                if (this.dialog.isShowing()) this.dialog.dismiss();
            }

    return list;
}

@Override
protected void onPostExecute(Object result) {
    if (this.dialog.isShowing()) this.dialog.dismiss();
}

}


Progress dialog is always used to show that there is some background task going on when the prgress dialog is showing . There is no purpose of progress dialog without this.

However you can use AsyncTask class as a substitute of thread and handler to show progress dialog in android.

See this for AsyncTask class.


Progress bar and progress dialog is different.

You can create progress bar through xml also. See the following code to craete progress bar

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/FIL_Main_RelativeLayout"
    android:background="#ffffff">
    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        style="@android:style/Widget.ProgressBar.Inverse"
        android:id="@+id/FIL_Middle_ProgressBar"></ProgressBar>
        </RelativeLayout>

Thanks Deepak

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜