I'm new to Java / Android development (I started learning last night), so it's entirely possible that I'm doing something terribly stupid. However, after more than an hour of googling, I came up with nothing. I use Eclipse as my editor.
I read the docs here for AlertDialog , which gives an example:
public static class MyAlertDialogFragment extends DialogFragment { public static MyAlertDialogFragment newInstance(int title) { MyAlertDialogFragment frag = new MyAlertDialogFragment(); Bundle args = new Bundle(); args.putInt("title", title); frag.setArguments(args); return frag; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { int title = getArguments().getInt("title"); return new AlertDialog.Builder(getActivity()) .setIcon(R.drawable.alert_dialog_icon) .setTitle(title) .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ((FragmentAlertDialog)getActivity()).doPositiveClick(); } } ) .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ((FragmentAlertDialog)getActivity()).doNegativeClick(); } } ) .create(); } }
I originally rewrote it, so I can start using some of the methods in memory, but I got the error "FragmentAlertDialog cannot be resolved to type". I pressed Ctrl + Shift + O to make sure that I have the correct import, but still it has not disappeared.
So, I copied / pasted the example code and did the following in the following order:
- Press Ctrl + Shift + O to get import rights (using
android.app.DialogFragment , not android.support.v4.app.DialogFragment ) - Announced my package at the top
- Replaced
R.string.alert_dialog_ok and R.string.alert_dialog_cancel with android.R.string.ok and android.R.string.cancel respectively - Removed
setIcon() since I don't have an icon to add
I still get errors:
FragmentAlertDialog cannot be allowed for type (x4)- Invalid modifier for class
MyAlertDialogFragment ; only public , abstract and final allowed
Am I doing something wrong or is something wrong with the sample code?
source share