ProgressDialog with custom view

In one of my application I had to download data from server which took almost 10-15 seconds and I didn’t want my users to stare at a progress dialog with just loading message.

I wanted to customize the default ProgressDialog to display interesting facts so that the user feels that they are waiting too long for the data.

My first step was to create my own layout and set the layout using the method setContentView method. But seems this method though available but cannot be used since it throws the following error

android.util.AndroidRuntimeException: requestFeature() must be called before adding content

So I tried to write my own dialog by sub classing Dialog but figured out that there is a better way by sub classing AlertDialog.

AlertDialog.Builder builder = new AlertDialog.Builder(context);
progressView = LayoutInflater.from(context).inflate(R.layout.progress_dyk, null);
builder.setView(progressView);
progress = builder.create();
progress.requestWindowFeature(Window.FEATURE_NO_TITLE);

progress.show();
7248 Total Views 8 Views Today