gpt4 book ai didi

java - AlertDialog在DialogFragment中不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 12:37:12 26 4
gpt4 key购买 nike

我对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();


我认为这对您有帮助。

关于java - AlertDialog在DialogFragment中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37205314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com