カスタムダイアログを作成しました。[OK]をクリックしたときに新しいアクティビティを開始したいと思います。インテントコンストラクターの最初の引数として設定するコンテキストを取得するにはどうすればよいですか?
を使用してインテントを作成できますが、をgetContext()
呼び出すことはできませんstartActivity
。ダイアログを呼び出すアクティビティをダイアログのコンストラクターに渡しますか?ダイアログをクリックしてアクティビティを開始する通常の方法ですか?
public class CustomDialog extends Dialog implements OnClickListener {
Button okButton, cancelButton;
public CustomDialog(Context context) {
super(context);
setContentView(R.layout.custom_dialog);
okButton = (Button) findViewById(R.id.button_ok);
okButton.setOnClickListener(this);
cancelButton = (Button) findViewById(R.id.button_cancel);
cancelButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == cancelButton)
dismiss();
else {
Intent i = new Intent(getContext(), ItemSelection.class);
startActivity(i); //The method startActivity(Intent) is undefined for the type CustomDialog
}
}
}