private void onSave() {
    if (eAmount.getText().length() > 0) {
      float amount = Float.parseFloat(eAmount.getText().toString());
      if (amount > 0.01) {
        iTransaction.setAmount(amount);

        AccountManager accountManager = AccountManager.getInstance();
        if (id == Constant.INVALID_ID) {
          iTransaction.setId(accountManager.insertTransaction(getContext(), iTransaction));
        } else {
          accountManager.updateTransaction(getContext(), iTransaction);
        }
        if (onWithdrawDialogListener != null) {
          onWithdrawDialogListener.onTransactionUpdated(iTransaction);
        }
      }
    }
    dismiss();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    id = Constant.INVALID_ID;
    long accountId = Constant.INVALID_ID;
    if (getArguments() != null) {
      accountId = getArguments().getLong(Constant.ARG_ACCOUNT_NUMBER_LONG);
      id = getArguments().getLong(Constant.ARG_TRANSACTION_NUMBER_LONG);
    }

    DataSourceTransaction dataSourceTransaction = new DataSourceTransaction(getContext());
    if (id != Constant.INVALID_ID) {
      iTransaction = dataSourceTransaction.getTransaction(id);
    } else {
      iTransaction = new ITransaction();
      iTransaction.setType(ITransaction.TRANSACTION_TYPE_ACCOUNT_WITHDRAW);
      iTransaction.setSubType(ITransaction.TRANSACTION_SUB_TYPE_ACCOUNT_BOTH);
      iTransaction.setAccount(accountId);
    }

    setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Material_Light_Dialog_MinWidth);
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.dialog_account_withdraw, container, false);

    Button bSave = (Button) rootView.findViewById(R.id.save);
    bSave.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onSave();
          }
        });

    ImageButton bClose = (ImageButton) rootView.findViewById(R.id.close);
    bClose.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            dismiss();
          }
        });

    eAmount = (EditText) rootView.findViewById(R.id.amount);
    if (iTransaction.getAmount() > 0.01) {
      eAmount.setText("" + iTransaction.getAmount());
    }

    final Button date = (Button) rootView.findViewById(R.id.date);
    date.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            final SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy");
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(iTransaction.getDate());
            DatePickerDialog datePicker =
                new DatePickerDialog(
                    getContext(),
                    new DatePickerDialog.OnDateSetListener() {
                      public void onDateSet(DatePicker datepicker, int year, int month, int day) {
                        Calendar cal = Calendar.getInstance();
                        cal.set(year, month, day);
                        if (DateUtils.isToday(cal.getTimeInMillis())) {
                          date.setText("TODAY");
                        } else {
                          date.setText(df.format(cal.getTime()));
                        }
                        iTransaction.setDate(cal.getTimeInMillis());
                      }
                    },
                    calendar.get(Calendar.YEAR),
                    calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DATE));
            datePicker.show();
          }
        });

    return rootView;
  }