Dialog使用总结

Dialog分三个区域

Title
Content area:不能同时放message和list
Action buttons:最多三个
创建AlertDialog.Builder对象

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

AlertDialog.Builder里面的方法

setTitle()
setMessage()
setPositiveButton()
setNegativeButton()
setNeutralButton()
create()

添加Button

setPositiveButton()
setNegativeButton()
setNeutralButton()
*

A traditional single-choice list 单选

setItems()

setItems(R.array.colors_array, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}

setAdapter(),可能还需要Loader异步加载数据
A persistent single-choice list (radio buttons) 单选
setSingleChoiceItems()
A persistent multiple-choice list (checkboxes) 多选
setMultiChoiceItems()
这里需要创建一个属性,存储点击的项目

 private ArrayList mSelectedItems;
            .setMultiChoiceItems(R.array.toppings, null,
                                      new DialogInterface.OnMultiChoiceClickListener() {
                               @Override
                               public void onClick(DialogInterface dialog, int which,
                                       boolean isChecked) {
                                   if (isChecked) {
                                       // If the user checked the item, add it to the selected items
                                       mSelectedItems.add(which);
                                   } else if (mSelectedItems.contains(which)) {
                                       // Else, if the item is already in the array, remove it 
                                       mSelectedItems.remove(Integer.valueOf(which));
                                   }
                               }
                           })

创建自定义布局

方法一:
创建xml布局文件
使用LayoutInflater创建布局文件的View
setView(…)
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_signin, null))
方法二:将activity作为dialog
创建一个activity
设置activity的xml属性

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值