AlertDialog dialog;
AlertDialog.Builder login_dialog;

LayoutInflater factory = LayoutInflater.from(A.this);
View v1 = factory.inflate(R.layout.control,null);

go_front =  (Button) v1.findViewById(R.id.button1);
go_front.setOnTouchListener(new ButtonTouch());

login_dialog = new AlertDialog.Builder(A.this);
login_dialog.setTitle("ED"+String.format("%02x", EDID));
login_dialog.setView(v1); // 設置使用view。
                          // 設置控件應該用v1.findViewById,否則會出錯。
login_dialog.setPositiveButton("關閉", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {

    }
});
login_dialog.show();

照上面的寫法,如果要關閉login_dialog,似乎一定要透過上面定義的關閉鈕來關閉,沒辦法透過其他的按鈕或事件來關閉它,AlertDialog.Builder沒有提供dismiss()或cancel()的語法,因此搜尋了一下,找到一種解法

把AlertDialog.Builder指向一個AlertDialog
dialog = login_dialog.show();

接下來如果要透過其他按鈕或事件來關閉,就可以利用dialog.dismiss()或dialog.cancel()的語法來運用即可。

 

 

arrow
arrow
    全站熱搜

    小彬彬 發表在 痞客邦 留言(0) 人氣()