I have a recyclerview that will have an option button to the right, and I want to achieve something like the animation below:
I'm using this as my reference but I have some disconnects.
First I want to know if I can even do this because every thing I find on adding a menu to a recyclerview is adding a basic menu pop up, which is not what I want.
I also have some disconnect on accessing the menu from the viewholder, I can access it from my fragment but I'd think I'd need to call it from the viewholder so I have what row clicked to fire up the menu.
If I'm overthinking the implementation and there's a simpler approach, I'm open to hearing it.
Im not sure if I am understanding what you want, but if it is to have a button that exist in the row items of the recyclerview to pop up a drawer from the bottom of the screen whenever the button is clicked, then you should just use a normal drawer setup (Navigation Drawer, Create a navigation drawer) for the activity and have an OnClickListener
added to the row buttons (which can be done in onCreateViewHolder()
or the holder's constructor) that triggers the drawer to open by calling openDrawer()
. Note to do the latter, you have to pass the navigation drawer (DrawerLayout
) into the adapter via the adaptors constructor (which means your adapter needs something to store the DrawerLayout
in).
So
public class CustomAdaptor extends RecyclerView.Adapter<CustomViewHolder>{
private Context mContext;
private int mLayoutResourceId;
private ArrayList<Item> items;
private DrawerLayout drawer;
public CustomAdaptor (Context context, int resource, ArrayList<Item> itemArray, DrawerLayout drawer) {
this.mContext = context;
this.mLayoutResourceId = resource;
this.items = itemArray;
this.drawer = drawer;
}
public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(mLayoutResourceId, parent, false);
final CustomViewHolder holder = new CustomViewHolder(view);
holder.mbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
//Check if drawer is null and if not then call
drawer.drawerOpen();
}
});
return holder;
}
}
where mButton
is the button in the holder/row. Note I havent tested this so there might be somethings im forgetting.