我对DialogFragment中的'onCreateDialog'有问题fmonday.java
代码(P.S .:我删除了一些代码以使其更短):
public class fmonday extends DialogFragment implements LoaderManager.LoaderCallbacks<Cursor> {
final int DIALOG_ITEMS = 1;
final CharSequence[] items = {"1", "2", "3"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fmonday, container, false);
Button button12 = (Button) rootView.findViewById(R.id.button12);
button12.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
getActivity().showDialog(DIALOG_ITEMS);
}
});
}
@Override //Error is on this line
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_ITEMS:
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
adb.setTitle("Adding class");
adb.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getActivity().getApplicationContext(),
"Your choice: " + items[item],
Toast.LENGTH_SHORT).show();
}
});
adb.setCancelable(false);
return adb.create();
default:
return null;
}
}
日志猫:
错误:(88,5)错误:方法未覆盖或从超类型实现方法
如何解决呢?
最佳答案
AlertDialog.Builder adb = new AlertDialog.Builder(ActivityName.this);
....
return adb.create();
代替
AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
....
return adb.create();
我认为这对您有帮助。