我有一个显示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
答案 0 :(得分:1)
使用MapView而不是MapFragment。 MapFragment有一些detatching问题,所以当你第二次打开对话框时,它会崩溃,因为第一个MapFragment仍然没有分离。
答案 1 :(得分: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();