[英]Codename One - event listener for Dialog dismiss/cancel/tap outside
我正在通過 Codename One 移植我的 Android 應用程序。
現在我在我的應用程序中移植對話框。
我能夠在 Codename 項目中創建類似的對話框,將 ActionListeners 添加到按鈕等等,但我無法找到用於取消/關閉/點擊外部事件的事件偵聽器。
dispose() 方法沒有相應的偵聽器,這很有用。
這是最簡單的對話框,但我也有更復雜的:
public static void openAlertDialog( String s1, String s2)
{
Dialog alertDialog=new Dialog(s1);
Button okButton=new Button("ok");
alertDialog.setLayout(BoxLayout.y());
Container c1=new Container(); //not so useful here but when there are more buttons
c1.setLayout(BoxLayout.x());
alertDialog.add(new SpanLabel(s2, "DialogBody"));
c1.add(okButton);
alertDialog.add(c1);
alertDialog.show();
}
當對話框被關閉但沒有按下按鈕時,如何有機會執行一些代碼?
您甚至不需要 Codename One 對話框的事件偵聽器。 例如,這段代碼可以這樣寫:
Dialog alertDialog=new Dialog(s1);
Command ok = new Command("ok");
Button okButton=new Button(ok);
alertDialog.setLayout(BoxLayout.y());
Container c1=new Container(); //not so useful here but when there are more buttons
c1.setLayout(BoxLayout.x());
alertDialog.add(new SpanLabel(s2, "DialogBody"));
c1.add(okButton);
alertDialog.add(c1);
alertDialog.setDisposeWhenPointerOutOfBounds(true);
if(alertDialog.showDialog() == ok) {
// user pressed OK. You can test against other commands than ok as well
} else {
// canceled or clicked outside
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.