Updated 11 September 2017
There are many situations where we show Error when the user does not input right Data. Such as filling the form, User Login etc.
So, How we show an Error message, through DataBinding?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<android.support.design.widget.TextInputLayout android:id="@+id/addBookTelephonelayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" app:error="@{billShipModel.BPhone.isEmpty() && billShipObsevable.billingShowError ? " Hii error find " : null}" android:layout_alignParentStart="true" android:layout_alignParentTop="true"> <EditText android:id="@+id/addBookTelephoneValue" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="30dp" android:hint="@string/telephone" android:text="@={billShipModel.BPhone}" android:inputType="phone" android:singleLine="true" android:textColorHint="@color/gray" /> </android.support.design.widget.TextInputLayout> |
1 2 3 4 5 6 7 8 9 10 11 |
@Bindable public String getBPhone() { return bPhone; } public void setBPhone(String bPhone) { this.bPhone = bPhone; notifyPropertyChanged(BR.bPhone); if(this.bPhone.equalsIgnoreCase("")) getBillingShippingBinder().setBillingAddressValidation(false); } |
1 2 3 4 5 6 7 8 9 |
@Bindable public boolean isBillingShowError() { return billingShowError; } public void setBillingShowError(boolean billingShowError) { this.billingShowError = billingShowError; notifyPropertyChanged(BR.billingShowError); } |
1 2 3 4 5 6 7 8 9 10 11 12 |
public void onSaveBillingShippingInfoIv(View view, BillingShippingModel billShipModelData, BillingShippingBinder billShipObservable){ Log.d(TAG, "onSaveBillingShippingInfoIv: 1" + billShipObservable.isBillingAddressValidation()); billShipObservable.setBillingShowError(true); if(billShipModelData.isFormValidated()){ saveProfile(billShipModelData); }else{ Log.d(TAG, "onSaveBillingShippingInfoIv: 3"); billShipObservable.setBillingShowError(false); } } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
If possible please include screens for each posts. So, that we can get to know how it looks.
Thank you for helping us.