構建器。我想在解僱或取消時執行一些操作。所以我使用setOnDismissListener
和setOnCancelListener
就像下面的代碼。但是這兩種方法都不能檢測何時解僱AlertDialog.Builder
。AlertDialog.Builder解僱不適用於API 17 android
private static void openOptionDialog(final Context context, Item[] items, String title, DialogInterface.OnClickListener positiveClick) {
ListAdapter adapter = new ArrayAdapter<Item>(
context, android.R.layout.select_dialog_item, items) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
Item item = getItem(position);
textView.setText(item.string);
textView.setTextSize(16f);
textView.setCompoundDrawablesWithIntrinsicBounds(item.icon, 0, 0, 0);
textView.setCompoundDrawablePadding(BDevice.getPixelFromDp(context, 15));
return view;
}
};
AlertDialog.Builder builder = AlertUtils.getBuilder(context);
builder.setTitle(title);
builder.setAdapter(adapter, positiveClick);
builder.create().show();
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
WidgetSettings preference = new WidgetSettings(context);
if(preference.canWidgetTooteets()){
preference.clear();
}
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
WidgetSettings preference = new WidgetSettings(context);
if(preference.canWidgetTooteets()){
preference.clear();
}
}
});
}
凡AlertUtils
getBuilder
方法如下,
public static AlertDialog.Builder getBuilder(Context context) {
return new AlertDialog.Builder(context, R.style.Dialog);
}
可否請你建議我找到了一個解決方案?提前致謝。
ü要使用Aleart或像Dismis或OK aleart按鈕進行操作? –
@RavishSharma我想在解散AlertDialog.Builder時執行一些操作。 – Sangeetha
@Sangeetha嘗試* AlertDialog *而不是* AlertDialog.Builder *並添加* setOnDismissListener *,因爲它可以工作。 –