Search in sources :

Example 11 with SafeListener

use of com.andframe.listener.SafeListener in project AndFrameWorks by scwang90.

the class AfDialogBuilder method selectItem.

/**
 * 显示一个单选对话框
 *
 * @param title    对话框标题
 * @param items    选择菜单项
 * @param listener 选择监听器
 * @param oncancel 取消选择监听器
 */
@Override
public Dialog selectItem(CharSequence title, CharSequence[] items, OnClickListener listener, final OnCancelListener oncancel) {
    Builder dialog = new Builder(mContext);
    if (title != null) {
        dialog.setTitle(title);
        if (oncancel != null) {
            dialog.setNegativeButton("取消", new SafeListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    oncancel.onCancel(dialog);
                }
            });
        }
    }
    if (oncancel != null) {
        dialog.setCancelable(true);
        dialog.setOnCancelListener(new SafeListener(oncancel));
    } else {
        dialog.setCancelable(false);
    }
    dialog.setItems(items, new SafeListener(listener));
    return dialog.show();
}
Also used : DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) DialogBuilder(com.andframe.api.DialogBuilder) SafeListener(com.andframe.listener.SafeListener) SuppressLint(android.annotation.SuppressLint)

Aggregations

SafeListener (com.andframe.listener.SafeListener)11 SuppressLint (android.annotation.SuppressLint)8 Builder (android.app.AlertDialog.Builder)7 DialogBuilder (com.andframe.api.DialogBuilder)7 AlertDialog (android.app.AlertDialog)6 TargetApi (android.annotation.TargetApi)5 DatePickerDialog (android.app.DatePickerDialog)5 TimePickerDialog (android.app.TimePickerDialog)5 Calendar (java.util.Calendar)5 Dialog (android.app.Dialog)4 ProgressDialog (android.app.ProgressDialog)4 DialogInterface (android.content.DialogInterface)4 OnCancelListener (android.content.DialogInterface.OnCancelListener)4 OnClickListener (android.content.DialogInterface.OnClickListener)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 LayoutParams (android.view.ViewGroup.LayoutParams)4 CheckBox (android.widget.CheckBox)4 DatePicker (android.widget.DatePicker)4 LinearLayout (android.widget.LinearLayout)4