@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { return null; } mainLayout = inflater.inflate(R.layout.full_order_fragment, null); if (getArguments() != null) { Date date = (Date) getArguments().getSerializable("execDate"); int orderId = getArguments().getInt("orderId", 0); if (date != null) { Order order = new Order(); order.setExecDate(date); showOrder(order); } else if (orderId != 0) { showOrder(Order.getOrderFromBase(orderId)); } } else { showOrder(new Order()); } return mainLayout; }
private void saveOrder(Order orderToSave) { valueList.put("_id", currentOrder.getOrderId()); for (EditText fieldToSave : editFields) { if (fieldToSave.getText() != null) { valueList.put(fieldToSave.getTag().toString(), fieldToSave.getText().toString()); } } orderToSave.setOrderValues(valueList); if (orderToSave.save()) { Toast toast = Toast.makeText( MainActivity.appContext, "Order " + orderToSave.getOrderId() + " saved", Toast.LENGTH_LONG); toast.show(); } }
public void showOrder(Order order) { currentOrder = order; valueList = currentOrder.getOrderValues(); editFields = new ArrayList<EditText>(); if (mainLayout != null) { Button saveButton = (Button) getActivity().findViewById(R.id.saveButton); saveButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { saveOrder(currentOrder); fragmentListener.saveOrderButtonClicked(); } }); CheckBox execStateCheckBox = (CheckBox) getActivity().findViewById(R.id.execStateCheckBox); execStateCheckBox.setChecked(currentOrder.getExecState()); execStateCheckBox.setOnCheckedChangeListener( new CheckBox.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { currentOrder.setExecState(isChecked); valueList.put("execState", isChecked); } }); EditText clientNameEdit = (EditText) mainLayout.findViewById(R.id.clientNameEdit); clientNameEdit.setOnKeyListener(onTextChanged); clientNameEdit.setOnFocusChangeListener(onFocusLost); clientNameEdit.setText(currentOrder.getClientName()); clientNameEdit.setTag("clientName"); editFields.add(clientNameEdit); EditText clientPhoneEdit = (EditText) mainLayout.findViewById(R.id.clientPhoneEdit); clientPhoneEdit.setOnKeyListener(onTextChanged); clientPhoneEdit.setOnFocusChangeListener(onFocusLost); clientPhoneEdit.setText(currentOrder.getClientPhone()); clientPhoneEdit.setTag("clientPhone"); editFields.add(clientPhoneEdit); EditText carMakerEdit = (EditText) mainLayout.findViewById(R.id.carMakerEdit); carMakerEdit.setOnKeyListener(onTextChanged); carMakerEdit.setOnFocusChangeListener(onFocusLost); carMakerEdit.setText(currentOrder.getCarMaker()); carMakerEdit.setTag("carMaker"); editFields.add(carMakerEdit); EditText colorCodeEdit = (EditText) mainLayout.findViewById(R.id.colorCodeEdit); colorCodeEdit.setOnKeyListener(onTextChanged); colorCodeEdit.setOnFocusChangeListener(onFocusLost); colorCodeEdit.setText(currentOrder.getColorCode()); colorCodeEdit.setTag("colorCode"); editFields.add(colorCodeEdit); EditText volumeBaseEdit = (EditText) mainLayout.findViewById(R.id.volumeBaseEdit); volumeBaseEdit.setOnKeyListener(onTextChanged); volumeBaseEdit.setOnFocusChangeListener(onFocusLost); volumeBaseEdit.setFilters(new InputFilter[] {new RealNumberInputFilter()}); volumeBaseEdit.setText(currentOrder.getVolumeBase().toString()); volumeBaseEdit.setTag("volumeBase"); editFields.add(volumeBaseEdit); EditText volumeAdditionEdit = (EditText) mainLayout.findViewById(R.id.volumeAdditionEdit); volumeAdditionEdit.setOnKeyListener(onTextChanged); volumeAdditionEdit.setOnFocusChangeListener(onFocusLost); volumeAdditionEdit.setFilters(new InputFilter[] {new RealNumberInputFilter()}); volumeAdditionEdit.setText(currentOrder.getVolumeAddition().toString()); volumeAdditionEdit.setTag("volumeAddition"); editFields.add(volumeAdditionEdit); EditText orderDateEdit = (EditText) mainLayout.findViewById(R.id.orderDateEdit); orderDateEdit.setOnKeyListener(onTextChanged); orderDateEdit.setOnFocusChangeListener(onFocusLost); orderDateEdit.setFilters(new InputFilter[] {new DateInputFilter()}); orderDateEdit.setText(currentOrder.getOrderDate().toString()); orderDateEdit.setTag("orderDate"); editFields.add(orderDateEdit); EditText execDateEdit = (EditText) mainLayout.findViewById(R.id.execDateEdit); execDateEdit.setOnKeyListener(onTextChanged); execDateEdit.setOnFocusChangeListener(onFocusLost); execDateEdit.setFilters(new InputFilter[] {new DateInputFilter()}); execDateEdit.setText(currentOrder.getExecDate().toString()); execDateEdit.setTag("execDate"); editFields.add(execDateEdit); NumberKeyListener realKeyListener = new NumberKeyListener() { @Override protected char[] getAcceptedChars() { return new char[] {'.', ',', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; } @Override public int getInputType() { return TYPE_CLASS_NUMBER | TYPE_NUMBER_FLAG_DECIMAL; } }; volumeBaseEdit.setKeyListener(realKeyListener); volumeAdditionEdit.setKeyListener(realKeyListener); } }