Reputation: 31
I have an adroid aplication that shows a Dialog
that displays some data when you tap the respective item in the listview
and works fine, but the second time I tap on another item, it crashes.
The list view calls an xml and inside I call a map fragment, that map fragment makes it crash, for some reason.
This is the 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>
Here I call open the dialog everytime there is a tap in the list.
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
}
Edit: This is the full error. Error is too large to add here http://prntscr.com/6gyng6
Upvotes: 1
Views: 894
Reputation: 7065
You have to dismiss the dialog every time. For example:
You can try both, either
dialog.cancel();
or
dialog.dismiss();
in the both implementation of setPositiveButton and 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();
Upvotes: 1
Reputation: 16463
Use MapView instead of MapFragment. MapFragment has some detatching problem, so when you open the dialog second time, it crashes because first MapFragment is still not detached.
Upvotes: 1