I have a RecyclerView, which has a Button and an EditText. I have a Button outside of the RecyclerView. On click the outside Button, I want the Button in the RecyclerView toggles between hide and show. How to do that?
I have tried to send a boolean parameter mEditFlag to the recyclerAdapter, toogle mEditFlag, and notify the adapter the data has changed. but it doesn't work.
mCurrentOrderRecyclerAdapter = new CurrentOrderRecyclerAdapter(this, mEditFlag);
rvOrder.setAdapter(mCurrentOrderRecyclerAdapter);
rlEditOrderList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mEditFlag = !mEditFlag;
mCurrentOrderRecyclerAdapter.notifyDataSetChanged();
if (mEditFlag) {
ivEditOrderList.setImageResource(R.drawable.order_edit_true);
tvEditOrderList.setText(R.string.order_edit_flag_true);
} else {
ivEditOrderList.setImageResource(R.drawable.order_edit_false);
tvEditOrderList.setText(R.string.order_edit_flag_false);
}
}
});
@Override
public void onBindViewHolder(OrderRecyclerViewHolder holder, final int position) {
if(editFlag) {
holder.rlLeftItemRvOrder.setVisibility(View.VISIBLE);
} else {
holder.rlLeftItemRvOrder.setVisibility(View.GONE);
}
holder.tvNumItemRvOrder.setText(position + "x");
holder.tvDesItemRvOrder.setText("holder.ivFoodItemRvOrder.setImageResource(R.drawable.drawer_menu)");
holder.ivFoodItemRvOrder.setImageResource(R.drawable.drawer_menu);
}
getContext(); //to get the activity context use this line. MyViewHolder dataObjectHolder = new MyViewHolder(view); //in this way you can use the holder object. } private void update_data(MyViewHolder holder) { holder. edittext1.
addItemDecoration(headerDecoration); The decoration is also reusable since there is no need to modify the adapter or the RecyclerView at all.
It's pretty simple, simply set the RecyclerView 's height to wrap_content . That's right.
You have to achieve it with your adapter layer.
The Button
outside the RecyclerView
has to update the item inside the adapter (for example a boolean).
Then notify the change to update (for example with the notifyItemChanged method) the RecyclerView
Somenthing like:
rlEditOrderList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Update the item inside the adapter
MyObject obj = mAdapter.getItem(position);
obj.myBoolean= true;
mAdapter.notifyItemChanged(position);
}
});
with an adapter like:
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private ArrayList<MyObject> mDataset;
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
//Get the item in the adapter
MyObject obj = getItem(position);
if(obj.myBoolean)
holder.mButtonView.setVisibile(View.VISIBLE);
else
holder.mButtonView.setVisibile(View.GONE);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With