Skip to content Skip to sidebar Skip to footer

How To Get Id By Clicking Fab Button

I am displaying a ordered food list. A FloatingActionButton is placed on each food item(productId) at the ordered list, and I want to show a rating alert dialog to let user rate th

Solution 1:

You can use interface to get the callback of the floating action button on your activity like this :-

In your adapter class

publicinterfaceOnRatingButtonClickListener{
  voidonRatingClick(int productId);
}

and you will register this interface object in constructor of your adapter like this:-

private OnRatingButtonClickListener mOnRatingClickListener;

publicOrderAdapter(OnRatingButtonClickListener listener){
 this.mOnRatingClickListener = listener;
}

and in onBindViewHolder, you will do this:-

holder.btnRating.setOnClickListener(new View.OnClickListener()  
 @Override
 public void onClick(View view){
    //interface objectmOnRatingClickListener.onRatingClick(order.getProductId());
 });

and implement this interface in your activity and show your rating dialog. you have to set the adapter like this :-

OrderAdapteradapter=newOrderAdapter(this);

and implements the interface in your activity and you will get the method in your activity like this:-

@OverridepubliconRatingClick(int productId){
  // here you will get the id of your product and you can show dialog here
}   

If any furthur query,you can ask.

Post a Comment for "How To Get Id By Clicking Fab Button"