0

How can I create the dialog preference in code ?

        MyDialog dialog=new MyDialog(getActivity() );
        dialog.setTitle("asd");
        dialog.setKey("key");
        dialog.getDialog().show();

This is in my xml file, and it works fine when called prom preference screen

<!-- Custom Dialog -->
    <com.pak.asd.MyDialog
        android:key="key" android:title="title"
        android:dialogTitle="title"
        android:negativeButtonText="no"
        android:positiveButtonText="yes" android:dialogMessage="message" />

this is my class

public class MyDialog extends DialogPreference {
    private Context c;

    public MyDialog(Context c)
    {
    //is null correct ?
        super(oContext,null);       
        this.oContext = oContext;
    }

    public MyDialog(Context c, AttributeSet attrs)
    {
        super(c, attrs);        
        this.c = c;
    }

}
Lukap
  • 31,523
  • 64
  • 157
  • 244
  • I see that the constructor is added now for API21, but will it throw an exception if we call `super(c,null)` in older platforms. What happened for your. – Samuel Oct 28 '16 at 01:36

1 Answers1

0

DialogPreference has no DialogPreference (Context context) constructor, so, why do you define a MyDialog(Context c) constructor? Usually, you don't need that constructor, just the second one.

I have never used DialogPreference before, but you should be able to create your custom class the same way as the base one.

thelawnmowerman
  • 11,956
  • 2
  • 23
  • 36
  • What have you tried? Look for DialogPreference uses in Java code, I have never used it. Any example would fit for your extended class, don't worry for it. – thelawnmowerman Feb 14 '13 at 12:28