gpt4 book ai didi

java - 方法 show(FragmentManager, String) 不适用于 show(FragmentManager, String) android?

转载 作者:行者123 更新时间:2023-12-02 06:39:51 24 4
gpt4 key购买 nike

我正在尝试获取一个对话框来警告用户应以横向模式查看屏幕。我有一个对话框类和我的 Activity 调用该对话框,但它提示 show(FragmentManager, String) 不适用于 show(FragmentManager, String)。

import my.application.dialogs.OrientationAlertDialog;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;

public class StationMapActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
OrientationAlertDialog dialog = new OrientationAlertDialog();
dialog.show(getSupportFragmentManager(), "String");
} else {
setContentView(R.layout.activity_station_map);
}
}
}

我的对话框类是:

import my.application.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

public class OrientationAlertDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.landscape_dialog_alert)
.setPositiveButton(R.string.landscape_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.out.println("OK");
}
})
.setNegativeButton(R.string.landscape_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
System.out.println("CANCEL");
}
});
return builder.create();
}
}

我调整了 android 对话框文档中的代码,所以我不确定还能在哪里寻找解决方案。

我尝试过的所有方法,当我按下按钮进入此 Activity 时,应用程序都会崩溃。

Log cat 不会打印任何有用的内容:

[2013-10-09 00:24:17 - my.application] ------------------------------
[2013-10-09 00:24:17 - my.application] Android Launch!
[2013-10-09 00:24:17 - my.application] adb is running normally.
[2013-10-09 00:24:17 - my.application] Performing my.application.MainActivity activity launch
[2013-10-09 00:24:24 - my.application] Application already deployed. No need to reinstall.
[2013-10-09 00:24:24 - my.application] Starting activity my.application.MainActivity on device 00194db94fb33f
[2013-10-09 00:24:25 - my.application] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=my.application/.MainActivity }
[2013-10-09 00:24:26 - my.application] Attempting to connect debugger to 'my.application' on port 8600

最佳答案

您正在使用 android.support.v4.app.DialogFragment,表明您正在尝试使用 Android 支持包的 fragment 反向移植。如果是这种情况,您需要使用 getSupportFragmentManager(),而不是 getFragmentManager()

关于java - 方法 show(FragmentManager, String) 不适用于 show(FragmentManager, String) android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19260418/

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