public void dialogSetQuantity(Context context, Product product) { final Dialog dialog = new Dialog(mContext, R.style.WideDialog); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); final DialogQuantityBinding mDialogBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.dialog_quantity, null, false); dialog.setContentView(mDialogBinding.getRoot()); mDialogBinding.edtQuantity.setText(String.valueOf(product.getTempQty())); mDialogBinding.edtQuantity.setSelection(mDialogBinding.edtQuantity.getText().length()); mDialogBinding.txtTitle.setText(product.getProductName()); mDialogBinding.txtCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); Utils.getInstance().hideKeyboard(v, mContext); } }); mDialogBinding.edtQuantity.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (Utils.validateString(mDialogBinding.edtQuantity.getText().toString().trim())) { int qty = Integer.parseInt(mDialogBinding.edtQuantity.getText().toString().trim()); if (qty > product.getQty()) { mDialogBinding.txtOk.setTextColor(mContext.getResources().getColor(R.color.divider_color)); mDialogBinding.txtOk.setEnabled(false); mDialogBinding.txtOk.setClickable(false); } else { if(qty < 1) { mDialogBinding.txtOk.setTextColor(mContext.getResources().getColor(R.color.divider_color)); }else{ mDialogBinding.txtOk.setEnabled(true); mDialogBinding.txtOk.setClickable(true); mDialogBinding.txtOk.setTextColor(mContext.getResources().getColor(R.color.black)); } } } } @Override public void afterTextChanged(Editable s) { } }); if (Utils.validateString(mDialogBinding.edtQuantity.getText().toString().trim())) { int qty = Integer.parseInt(mDialogBinding.edtQuantity.getText().toString().trim()); if (qty > product.getQty()) { mDialogBinding.txtOk.setTextColor(mContext.getResources().getColor(R.color.divider_color)); mDialogBinding.txtOk.setEnabled(false); mDialogBinding.txtOk.setClickable(false); } else { mDialogBinding.txtOk.setEnabled(true); mDialogBinding.txtOk.setClickable(true); mDialogBinding.txtOk.setTextColor(mContext.getResources().getColor(R.color.black)); } } mDialogBinding.txtMessage.setText(mContext.getResources().getString(R.string.please_enter_quantity_between) + " " + product.getQty()); mDialogBinding.txtOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Utils.validateString(mDialogBinding.edtQuantity.getText().toString().trim())) { int qty = Integer.parseInt(mDialogBinding.edtQuantity.getText().toString().trim()); if (qty > product.getQty()) { mDialogBinding.txtOk.setTextColor(mContext.getResources().getColor(R.color.divider_color)); } else { dialog.dismiss(); mDialogBinding.txtOk.setTextColor(mContext.getResources().getColor(R.color.black)); product.setTempQty(Integer.parseInt(mDialogBinding.edtQuantity.getText().toString().trim())); int pos = alstProduct.indexOf(product); alstProduct.set(pos, product); notifyDataSetChanged(); } } } }); dialog.show();}
=======================
dialog_quantity.xml
<?xml version="1.0" encoding="utf-8"?><layout xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/dp20" android:background="@android:color/transparent" android:gravity="center" android:orientation="vertical"> <LinearLayout android:id="@+id/lyt_main" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/profile_ractangle_box" android:orientation="vertical" android:paddingBottom="@dimen/dp10" android:paddingLeft="@dimen/dp10" android:paddingRight="@dimen/dp10"> <TextView android:id="@+id/txtTitle" fontPath="fonts/Poppins-Medium.ttf" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="@dimen/dp10" android:layout_marginRight="@dimen/dp10" android:layout_marginTop="@dimen/dp10" android:gravity="center" android:text="" android:textColor="@color/white" android:textSize="@dimen/sp20" /> <TextView android:id="@+id/txtMessage" fontPath="fonts/Poppins-Medium.ttf" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="@dimen/dp10" android:layout_marginRight="@dimen/dp10" android:gravity="center" android:text="" android:textColor="@color/white" android:textSize="@dimen/sp16" /> <EditText android:id="@+id/edt_quantity" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/dp15" android:background="@drawable/edittext_remark" android:gravity="center|left" android:inputType="number" android:maxLines="5" android:maxLength="5" android:paddingBottom="@dimen/dp5" android:paddingLeft="@dimen/dp10" android:paddingRight="@dimen/dp10" android:paddingTop="@dimen/dp5" android:singleLine="false" android:textColor="@color/black" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingBottom="@dimen/dp10"> <TextView android:id="@+id/txt_ok" style="@style/txtDialogTextStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:text="@string/btn_ok" /> <TextView android:id="@+id/txt_cancel" style="@style/txtDialogTextStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:text="@string/btn_cancel" /> </LinearLayout> </LinearLayout> </LinearLayout></layout>
No comments:
Post a Comment