Android: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();`
通过语句 new Boolean [] {false,true,false false false false,true}
默认情况下,对话框中的项目
将被选中/取消选中。
Through the statement "new Boolean[] { false, true, false false false false, true }
" the items
in the dialog get checked/unchecked by default.
当我打开对话框时,更改项目的选择,然后关闭(通过按取消或设备的后退按钮)对话框被关闭。
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.
但是当第一次打开时对话框被拒绝时,我想让项目被选中/取消选中状态,就像我创建对话框一样( new Boolean [] {false,true,false false false false,true}
)。
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 }
).
所以基本上我需要一个机会,当对话被拒绝时,所以我可以重新设置项目的状态。
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在模拟器(API 17)中为我(在我需要的情况下,我需要什么),而不是在我的设备上(Android 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?
推荐答案
问题是您正在使用 setOnDismissListener
AlertDialog.Builder
。这是在api级别1中的Api级别17中引入的 setOnDismissListener
AlertDialog
b
$ b
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();`
这篇关于Android:setOnDismissListern API低于17的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!