Updated 8 July 2017
What is a Dialog in Android?
Dialog-
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for model events that require users to take an action before they can proceed.
When are we creating our application by using Data Binding then how we use Data Binding in a custom dialog?
We just follow three steps to implement databinding in Dialog and attach our model to dialog Layout.
1 2 |
Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); |
1 2 |
reviewBinding = (CustomReviewDialogBinding)DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.custom_review_dialog, null, false); dialog.setContentView(reviewBinding.getRoot()); |
1 2 3 4 5 |
productReview = new ProductReviewDialog(); reviewBinding.setType(type); reviewBinding.setHandler(this); reviewBinding.setProductReview(productReview); dialog.show(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
public class AllReviewHandler { private final Context mContext; private final int productId; private String currentRating, type; private CustomReviewDialogBinding reviewBinding; private ProductReviewDialog productReview;// model Dialog dialog; private SweetAlertDialogUtil progressDialog; public AllReviewHandler(Context context, int productId){ mContext = context; this.productId = productId; } public void onClickAddReview(View view, String type){ dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); reviewBinding = (CustomReviewDialogBinding)DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.custom_review_dialog, null, false); dialog.setContentView(reviewBinding.getRoot()); productReview = new ProductReviewDialog(); reviewBinding.setType(type); reviewBinding.setHandler(this); reviewBinding.setProductReview(productReview); dialog.show(); } public void onClickCancle(View v){ dialog.dismiss(); } public void onClickSubmit(View v, String type){ boolean isFormValidate = true; if(productReview.getCustomerName() == null || productReview.getCustomerName().isEmpty()) { productReview.setCustomerNameError(true); isFormValidate = false; } if(!type.equalsIgnoreCase("R") && (productReview.getComment()== null || productReview.getComment().isEmpty())) { productReview.setCommentErro(true); isFormValidate = false; } if(isFormValidate){ progressDialog = new SweetAlertDialogUtil(mContext); progressDialog.loading(mContext.getString(R.string.please_wait)); submitYourReview(); } } } |
Dismissing Custom Dialog-
The system also dismisses the dialog when the user touches an item in a dialog list, except when the list uses radio buttons or checkboxes. Otherwise, We can manually dismiss our dialog by calling dismiss();
We can also dismiss our Custom Dialog as normally we dismiss without DataBinding.
1 |
dialog.dismiss(); |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
2 comments
For more data Binding click here