När du sätter en egen vy på AlertDialog måste du ta bort den också för att kunna anropa show() igen senare. Kanske finns det andra sätt men det här funkar i alla fall. Grejen är alltså att anropa ((ViewGroup)layoutView.getParent()).removeView(layoutView) när dialogen stängs:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
final View layoutView = inflater.inflate(R.layout.may_layout, null);
final AlertDialog.Builder dlg = new AlertDialog.Builder(context)
.setTitle(R.string.my_dialog_title)
.setView(layoutView);
dlg.setPositiveButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
// do some fun
((ViewGroup)layoutView.getParent()).removeView(layoutView);
}
});
dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
((ViewGroup)layoutView.getParent()).removeView(layoutView);
}
});
// Vad du nu vill koppla ett klick till
xxx.setOnClickListener(
new OnClickListener() {
public boolean onClick(Preference preference) {
dlg.show();
return true;
}
}
);