/** * 给spinner添加默认的数据 * * @param event * @return */ private ArrayList<IllnessInfo> addTitle(List event) { IllnessInfo illnessInfo = new IllnessInfo(); illnessInfo.setName("点击选择"); ArrayList<IllnessInfo> objects = new ArrayList(event); objects.add(0, illnessInfo); return objects; }
/** * 显示剂量编辑框的dialog * * @param view1 显示剂量编辑框 * @param viewheshu1 显示剂量单位编辑框 * @param view2 显示盒数的编辑框 * @param viewheshu2 显示规格的编辑框 * @param nextView 下一个要弹出的spinner */ public void showEditDialog( final View view1, final View viewheshu1, final View view2, final View viewheshu2, final View nextView) { if (!(view1 instanceof TextView) || !(viewheshu1 instanceof TextView)) { return; } if (!(view2 instanceof TextView) || !(viewheshu2 instanceof TextView)) { return; } View rootView = getActivity().getLayoutInflater().inflate(R.layout.dialog_number_complex, null); final NumberPicker np1 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex1); final NumberPicker np2 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex2); final NumberPicker np3 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex3); final NumberPicker np4 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex4); final TextView tvDian = (TextView) rootView.findViewById(R.id.tv_dialog_complex_dian); final NumberPicker little = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex_little); final EditText et = (EditText) rootView.findViewById(R.id.et_dialog_complex); IllnessInfo illnessInfo = (IllnessInfo) spinnerTellMedical3.getSelectedItem(); // 诺和力剂量需要小数点 if (illnessInfo.getId().equals("1022")) { tvDian.setVisibility(View.VISIBLE); little.setVisibility(View.VISIBLE); } final TextView tv = (TextView) rootView.findViewById(R.id.tv_dialog_dost); final NumberPicker np5 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex5); final NumberPicker np6 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex6); final NumberPicker np7 = (NumberPicker) rootView.findViewById(R.id.np_dialog_complex7); np1.setMaxValue(5); np1.setMinValue(0); np2.setMaxValue(9); np2.setMinValue(0); np3.setMaxValue(9); np3.setMinValue(0); little.setMinValue(0); little.setMaxValue(9); np5.setMaxValue(5); np5.setMinValue(0); np6.setMaxValue(9); np6.setMinValue(0); np7.setMaxValue(9); np7.setMinValue(0); // 设置规格的数据 if (!TextUtils.isEmpty(((TextView) viewheshu2).getText())) { tv.setText(((TextView) viewheshu2).getText()); } // 如果剂量数值是double类型 if (CommonUtil.isStr2Num(((TextView) view1).getText().toString())) { final double defaultValues1 = TextUtils.isEmpty(((TextView) view1).getText()) ? 000.00 : Double.parseDouble(((TextView) view1).getText().toString()); np1.setValue((int) (defaultValues1 / 100)); np2.setValue((int) (defaultValues1 * 100 % 10000 / 1000)); np3.setValue((int) (defaultValues1 * 100 % 1000 / 100)); little.setValue((int) (defaultValues1 * 100 % 100 / 10)); } else { et.setText(((TextView) view1).getText()); } // 如果固定单位数组中没有新的,则添加 if (!defaultDost.contains(((TextView) viewheshu1).getText())) { defaultDost.add(((TextView) viewheshu1).getText().toString()); } // 默认的索引 int index = defaultDost.indexOf(((TextView) viewheshu1).getText().toString()); np4.setDisplayedValues(defaultDost.toArray(new String[defaultDost.size()])); np4.setMinValue(0); np4.setMaxValue(defaultDost.size() - 1); np4.setValue(index); final double defaultValues2 = TextUtils.isEmpty(((TextView) view2).getText()) ? 000.00 : Double.parseDouble(((TextView) view2).getText().toString()); np5.setValue((int) (defaultValues2 / 100)); np6.setValue((int) (defaultValues2 * 100 % 10000 / 1000)); np7.setValue((int) (defaultValues2 * 100 % 1000 / 100)); MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) .customView(rootView, false) .autoDismiss(false) .cancelable(false) .positiveText("确定") .negativeText("取消") .neutralText("重置") .onPositive( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { String aValue1, aValue1_dian = "", aValue2; if (view1 instanceof TextView && view2 instanceof TextView) { // 格式化小数点之前的数 if (np1.getValue() == 0) { if (np2.getValue() == 0) { aValue1 = String.valueOf(np3.getValue()); } else { aValue1 = String.valueOf(np2.getValue()) + String.valueOf(np3.getValue()); } } else { aValue1 = String.valueOf(np1.getValue()) + String.valueOf(np2.getValue()) + String.valueOf(np3.getValue()); } // 格式化小数点之后的数 if (little.getValue() != 0) { aValue1_dian = "." + little.getValue(); } // 格式化小数点之前的数 if (np5.getValue() == 0) { if (np6.getValue() == 0) { aValue2 = String.valueOf(np7.getValue()); } else { aValue2 = String.valueOf(np6.getValue()) + String.valueOf(np7.getValue()); } } else { aValue2 = String.valueOf(np5.getValue()) + String.valueOf(np6.getValue()) + String.valueOf(np7.getValue()); } ((TextView) view1).setText(aValue1 + aValue1_dian); ((TextView) view2).setText(aValue2); CommonUtil.hideSoftInputView(getActivity(), np1); CommonUtil.hideSoftInputView(getActivity(), np2); CommonUtil.hideSoftInputView(getActivity(), np3); CommonUtil.hideSoftInputView(getActivity(), np4); CommonUtil.hideSoftInputView(getActivity(), np5); CommonUtil.hideSoftInputView(getActivity(), np6); CommonUtil.hideSoftInputView(getActivity(), np7); dialog.dismiss(); if (!TextUtils.isEmpty(et.getText())) { ((TextView) view1).setText(et.getText()); } else { spinnerTellMedical6.setAdapter( new ArrayAdapter<>( getActivity(), R.layout.spinner_list_item, getResources().getStringArray(R.array.medic_blfy))); nextView.performClick(); } } } }) .onNeutral( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { np1.setValue(0); np2.setValue(0); np3.setValue(0); np5.setValue(0); np6.setValue(0); np7.setValue(0); et.setText(""); } }) .onNegative( new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { CommonUtil.hideSoftInputView(getActivity(), np1); CommonUtil.hideSoftInputView(getActivity(), np2); CommonUtil.hideSoftInputView(getActivity(), np3); CommonUtil.hideSoftInputView(getActivity(), np4); CommonUtil.hideSoftInputView(getActivity(), np5); CommonUtil.hideSoftInputView(getActivity(), np6); CommonUtil.hideSoftInputView(getActivity(), np7); CommonUtil.hideSoftInputView(getActivity(), et); dialog.dismiss(); } }) .build(); dialog.show(); // 关闭自动弹出输入法 CommonUtil.resetDialogParam(getActivity(), dialog); }