安卓:setOnDismissListern的API比17低 [英] Android: setOnDismissListern for API lower than 17
问题描述
我创建了一个AlertDialog:
I created an AlertDialog:
private CharSequence[] _items = { "item1", "item2", "item3", "item4",
"item5", "item6", "item7" };
AlertDialog.Builder daysBuilder = new AlertDialog.Builder(this);
daysBuilder.setTitle("SomeCaption");
daysBuilder.setMultiChoiceItems(_items,new Boolean[] { false, true, false,
false false false, true }, SetListener);
daysBuilder.setPositiveButton("OK", OKListener);
daysBuilder.setNegativeButton("Cancel", CancelListener);
AlertDialog alert = daysBuilder.create();
alert.show();`
通过声明新布尔[] {假,真,假假假假,真}
项目
在对话框中得到选中/取消选中默认情况下。
Through the statement "new Boolean[] { false, true, false false false false, true }
" the items
in the dialog get checked/unchecked by default.
当我打开的对话框中,改变了项目的选择,但随后驳回(由pressing取消或设备的后退按钮)对话框被驳回。到目前为止好。
When I open the dialog, change the selection of the items but then dismiss (by pressing cancel or the back-button of the device) the dialog gets dismissed. So far so good.
但是,当我重新打开的对话框中,该项目已被检查从对话框的最后开放。
But when I reopen the dialog, the items have the checked/unchecked state of the previous changes from the last opening of the dialog.
但是,当被dissmissed在第一次打开对话框,我想拥有的物品选中/取消选中状态,就像当我创建对话框(新布尔[] {假的,真的,假的假的假的假的,真}
)。
But when the dialog was dissmissed at the first opening, I want to have the items checked/unchecked state like when I created the dialog (new Boolean[] { false, true, false false false false, true }
).
因此,基本上,我需要一个机会,让notfied时被dissmissed对话,所以我就可以重新设置的项目状态。
So basically I need an opportunity to get notfied when the dialog gets dissmissed so I can then reset the state of the items.
我尝试了与setOnDismissListener的对话框对象。遗憾的是这仅仅是API 17可用。
I tried it with the setOnDismissListener for the dialog object. Unfortunately this is just available in API 17.
setOnDismissListener工作PERFEKT我(excactelly什么,我需要)在模拟器(API 17),但不是在我的设备(安卓4.1 => API 16)
setOnDismissListener worked perfekt for me (excactelly what I need) in the emulator (API 17) but not on my device (Android 4.1 => API 16)
有没有在API 16类似的东西?
Is there something similar in API 16?
推荐答案
现在的问题是,你正在使用AlertDialog.Builder的setOndismissListener。这是在API级别17引入的,AlertDialog本身setOndismissListener一直以来API级别1。
The problem is you are using setOndismissListener of AlertDialog.Builder. This was introduced in Api level 17, setOndismissListener of AlertDialog itself has been since api level 1.
AlertDialog alert = daysBuilder.create();
alert.setOndismissListener(yourdismisslistener);
alert.show();`
这篇关于安卓:setOnDismissListern的API比17低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!