Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create progress dialog with another layout

I want to create a progress dialog which inflates another XML file.

So I tried the following code

public class MyProgressDialog extends AlertDialog {

        public MyProgressDialog(Context context) {
            super(context,R.layout.customprog);

            // TODO Auto-generated constructor stub
        }

    }
MyProgressDialog pdia=new MyProgressDialog(this);

And in asynctask to show this is used pdia.show(); in onPreExecute()

porgspin.xml

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress1"
android:pivotX="50%"
android:pivotY="50%" />

customprog.xml

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:padding="10dp" >

        <ProgressBar
            android:id="@+id/imageView1"
            android:indeterminateDrawable="@drawable/porgspin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/progress" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="41dp"
            android:layout_toRightOf="@+id/imageView1"
            android:text="Loading..."
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000" />

    </RelativeLayout>

When I run the program I am unable to view the progress bar.

What am I missing here?

like image 514
krishna Avatar asked Jan 14 '23 01:01

krishna


2 Answers

Second parameter of super(context,R.layout.customprog) accepts a theme resource not a layout. Why don't you inflate the layout instead?

public class MyProgressDialog extends AlertDialog 
{

       @Override
       public void show() {

        super.show();
        setContentView(R.layout.activity_main);
       }

}
like image 118
Glenn Avatar answered Jan 22 '23 04:01

Glenn


Instead of passing your custom layout in constructor, override onCreate() method of dialog and use setContentView() method to pass your custom layout..

like image 43
Rakesh Bhalani Avatar answered Jan 22 '23 04:01

Rakesh Bhalani