AlertDialog的简单封装

//在fragment中调用
public class CeshiFragment extends Fragment {
    private int a[]={R.id.tv_air_unlimited,R.id.tv_air_economics,
            R.id.tv_air_super,R.id.tv_air_official,R.id.tv_air_frist};
    private String b[]={"舱位不限","经济舱","超级经济舱","公务舱","头等舱"};
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_ceshi, container, false);
        initView(view);
        return view;
    }
    private void initView(View view) {
        tv_sj = (TextView) view.findViewById(R.id.tv_sj);
        tv_sj.setText("测试数据测试数据测试数据测试数据测试数据");
        //dialog的使用
        tv_sj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialogUtils alertDialogUtils=new AlertDialogUtils(getActivity(),R.layout.alert_dialog_item);
                for(int i=0;i
package utils;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

/**
 * Created by haoyan on 2016/4/20.
 */
public class AlertDialogUtils {
    private Context mContext;
    private int layoutId;
    private DialogClickListener dialogClickLintener = null;
    private View view;
    //用于判断显示模式
    public static final int
            SHOW_MOD_YES = 0x00000001,
            SHOW_MOD_NO = 0x00000002;
    private  int showMode = SHOW_MOD_YES + SHOW_MOD_NO;
    public AlertDialogUtils(Context context, int layoutId){
        this.mContext = context;
        this.layoutId = layoutId;
        AlertDialog.Builder build = new AlertDialog.Builder(context);
        build.setTitle("舱位选择");
        LayoutInflater inflate = LayoutInflater.from(context);
        view = inflate.inflate(layoutId, null);
        build.setView(view);
        build.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                if(dialogClickLintener != null){
                    dialogClickLintener.clickYes();
                }
            }
        });
        build.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                if(dialogClickLintener != null){
                    dialogClickLintener.clickNo();
                }
            }
        });
        build.create().show();
    }
    public View getview(int viewId){
        return view.findViewById(viewId);
    }
    public View getContentView(){
        return view;
    }
    //外类调用这两个以确定显示模式
    public void setDialogButtonShowMode(int showMode){
        this.showMode = showMode;
    }
    private void showDialogButton(){
        if((showMode & SHOW_MOD_YES) == SHOW_MOD_YES){
            //TODO
        }else{

        }
        if((showMode & SHOW_MOD_NO) == SHOW_MOD_NO){

        }else{

        }
    }
    /**
     * 设置TextView的值
     * @param viewId
     * @param text
     * @return
     */
//    public AlertDialogUtils setText(int viewId[], String text[], View.OnClickListener[] clickListener){
//
//        for (int i=0;i

你可能感兴趣的:(android客户端,java语言)