SRINIVAS RAO
SRINIVAS RAO

Reputation: 219

i cannot see my custom progress dialog

I tried the following code for creating a custom progress dialog. But I am not getting the desired output.

Following is my MainActivity.java code

public class MainActivity extends Activity {

private ProgressDialog mProgressDialog;  

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
     @Override
        protected Dialog onCreateDialog(int id) {
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
mProgressDialog.setTitle(R.string.select_dialog);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    return mProgressDialog;
}   }

The strings.xml file as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="select_dialog">Sample</string>
<string name="select_dialog_show">List dialog</string>
<string name="app_name">Dialog</string>
</resources>

The activity_main.xml is as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity" >     
</RelativeLayout>

The DialogManifest.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.sample.dialog"
 android:versionCode="1"
 android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="1"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.sample.dialog.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Upvotes: 1

Views: 192

Answers (1)

Talha
Talha

Reputation: 12717

Hi please refer this URL

When you create an custom view you should give your custom layout to dialog like below

dialog.setContentView(R.layout.maindialog);

Upvotes: 1

Related Questions