日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

android dialog的封装,Android Dialog 简单封装

發(fā)布時間:2024/9/30 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android dialog的封装,Android Dialog 简单封装 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)載:https://www.cnblogs.com/zjjne/archive/2013/10/03/3350382.html

public class MyAlertDialog {

//region 確認/取消 彈出框

//取消按鈕,默認canel

public static Dialog createConfirmDialog(Context context, String title, String message,

String positiveBtnName, String negativeBtnName, DialogInterface.OnClickListener positiveBtnListener) {

Dialog dialog = null;

AlertDialog.Builder builder = new AlertDialog.Builder(context);

//設(shè)置對話框標(biāo)題

builder.setTitle(title);

//設(shè)置對話框消息

builder.setMessage(message);

//設(shè)置確定按鈕

builder.setPositiveButton(positiveBtnName, positiveBtnListener);

//設(shè)置取消按鈕

builder.setNegativeButton(negativeBtnName, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.cancel();

}

});

//創(chuàng)建一個消息對話框

dialog = builder.create();

return dialog;

}

//自定義取消按鈕事件

public static Dialog createConfirmDialog(Context context, String title, String message,

String positiveBtnName, String negativeBtnName, DialogInterface.OnClickListener positiveBtnListener,

DialogInterface.OnClickListener negativeBtnListener) {

Dialog dialog = null;

AlertDialog.Builder builder = new AlertDialog.Builder(context);

//設(shè)置對話框標(biāo)題

builder.setTitle(title);

//設(shè)置對話框消息

builder.setMessage(message);

//設(shè)置確定按鈕

builder.setPositiveButton(positiveBtnName, positiveBtnListener);

//設(shè)置取消按鈕

builder.setNegativeButton(negativeBtnName, negativeBtnListener);

//創(chuàng)建一個消息對話框

dialog = builder.create();

return dialog;

}

//endregion

//region 單選 彈出框

public static Dialog createRadioDialog(Context context, String title, final String[] ss , DialogInterface.OnClickListener btnListener) {

Dialog dialog = null;

AlertDialog.Builder builder = new AlertDialog.Builder(context);

//設(shè)置對話框標(biāo)題

builder.setTitle(title);

builder.setSingleChoiceItems(ss, 1, btnListener);

//創(chuàng)建一個消息對話框

dialog = builder.create();

return dialog;

}

//endregion

}

調(diào)用方式:

點擊btn按鈕時,彈出對話框。

確認后,執(zhí)行你的方法();

調(diào)用確認框

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Dialog dialog = MyAlertDialog.createConfirmDialog(InboundPOActivity.this, "提交", "入庫確認", "確定", "取消",

new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

你的方法();

}

});

dialog.show();

}

});

調(diào)用單選框

final String[] ss={"1","2","3"};

Dialog dialog = MyAlertDialog.createRadioDialog(InboundPOActivity.this,"Test",ss,new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

Toast.makeText(InboundPOActivity.this, "性別為:" + ss[which], Toast.LENGTH_SHORT).show();

}

});

dialog.show();

總結(jié)

以上是生活随笔為你收集整理的android dialog的封装,Android Dialog 简单封装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。