0

コードでダイアログ設定を作成するにはどうすればよいですか?

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

これは私のxmlファイルにあり、prom設定画面を呼び出すと正常に動作します

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

これは私のクラスです

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;
    }

}
4

1 に答える 1

0

DialogPreferenceコンストラクターがないDialogPreference (Context context)のに、なぜMyDialog(Context c)コンストラクターを定義するのですか?通常、そのコンストラクターは必要ありません。2番目のコンストラクターだけです。

これまで使用DialogPreferenceしたことはありませんが、基本クラスと同じ方法でカスタムクラスを作成できるはずです。

于 2013-02-14T12:17:46.367 に答える