AlertDialog.Builder的使用

//选择
private void selectSchool() {
    ArrayList list = new ArrayList<>();
    for (int i = 0; i < mListArea.size(); i++) {
        list.add(mListArea.get(i).getArea_name());
    }
    arr = list.toArray(new String[list.size()]);
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    //设置标题
    builder.setTitle("请选择");
    //设置图标
    builder.setItems(arr, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            tvSearch.setText(arr[i]);

            if (StringUtils.isEmpty(arr[i]) || arr[i].contains("全部")) {
                //区域ID(必须 默认可传0)
                PreferencesUtils.putString(getActivity(), KEY.AREAID, "");
            } else {
                //区域ID(必须 默认可传0)
                PreferencesUtils.putString(getActivity(), KEY.AREAID, mListArea.get(i).getId());
            }
            //选中学校
            PreferencesUtils.putString(getActivity(), KEY.AREAName, mListArea.get(i).getArea_name());
            headindex1();
        }
    });
    builder.create();
    builder.show();
}

你可能感兴趣的:(使用方式)