【问题标题】:My android aplication crashes a second time I load a dialog我的 android 应用程序在我第二次加载对话框时崩溃
【发布时间】:2015-05-17 10:03:00
【问题描述】:

我有一个显示Dialog 的adroid 应用程序,当您点击listview 中的相应项目时会显示一些数据并且工作正常,但是当我第二次点击另一个项目时,它会崩溃。

列表视图调用一个 xml,在里面我调用一个地图片段,该地图片段使其崩溃,出于某种原因。

这是itemlistdialog

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">
    <fragment
        android:layout_width="match_parent"
        android:layout_height="285dp"
        android:name="com.google.android.gms.maps.MapFragment"
        android:id="@+id/map" />
</LinearLayout>

这里我每次点击列表时都会调用打开对话框。

lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        LayoutInflater factory = LayoutInflater.from(this);
        View listDialogView = factory.inflate(R.layout.itemlistdialog, null);

        Dialog d = new AlertDialog.Builder(aux,AlertDialog.THEME_HOLO_LIGHT)
        //HERE I ADD THE DATA THAT WILL BE DISPLAYED IN THE DIALOG
}

编辑: 这是完整的错误。 错误太大,无法在此处添加 http://prntscr.com/6gyng6

【问题讨论】:

  • 发布(添加到问题中)您的 Logcat。
  • 对不起,我不明白。
  • 我们要求您发布应用程序崩溃时出现的 logcat 窗口中的错误
  • 由于某种原因我的电脑无法运行任何模拟器,所以我使用设备来测试应用程序。

标签: java android xml android-fragments


【解决方案1】:

您每次都必须关闭对话框。 例如:

两个都可以试试

dialog.cancel();

dialog.dismiss();

在 setPositiveButton 和 setNegativeButton 的实现中。

AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
            builder1.setMessage("Write your message here.");
            builder1.setCancelable(true);
            builder1.setPositiveButton("Yes",
                    new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            builder1.setNegativeButton("No",
                    new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });

            AlertDialog alert11 = builder1.create();
            alert11.show();

【讨论】:

    【解决方案2】:

    使用 MapView 代替 MapFragment。 MapFragment 有一些分离问题,所以当你第二次打开对话框时,它会崩溃,因为第一个 MapFragment 仍然没有分离。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 2011-05-27
      • 2021-03-20
      相关资源
      最近更新 更多