我现在正在使用IntelliJ学习Android编程,但遇到了一些问题。
我有一个活动,看起来像这样:
public class example2 extends Activity {
...some code...
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.optExit:
finish();
return true;
case R.id.optSettings:
Intent sintent = new Intent(this, settings.class);
startActivity(esintent);
return true;
case R.id.optAbout:
//need to start the fragmentdialog
}
return true;
}
...some code...
}
Run Code Online (Sandbox Code Playgroud)
这就是我的DialogFragment的样子
public class about extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setTitle("About");
b.setMessage("some text");
b.setCancelable(false);
b.setPositiveButton("OK", null);
return b.create();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了几乎所有内容,使用FragmentManager创建了一个新实例并启动了该方法,但我无法使用它。我该怎么办?