Hide Button If Not Data In Recyclerview
I had created a app in which i have multiple edittext and one buttonwith recyclerviuew and one button which are setvisibilty as Gone.On Button click it add all my data in my recycl
Solution 1:
you can use an interface to inform the fragment/activity, the list is empty. Adapter like as below:
publicclassCustomAdapterextendsRecyclerView.Adapter<CustomViewHolder> {
AdapterListener listener;
publicvoidsetListener(AdapterListener listener) {
this.listener = listener;
}
...
@OverridepublicvoidonBindViewHolder(@NonNull Myviewholder holder, finalint position) {
...
holder.delete.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
...
// remove your item from data base
laand_list.remove(position); // remove the item from list
notifyItemRemoved(position); // notify the adapter about the removed itemif (laand_list.size()==0)
listener.onDataListIsEmpty();
}
});
}
publicinterfaceAdapterListener {
voidonDataListIsEmpty();
}
}
The Activity/Fragment like as below:
classMyActivityextendsActivityimplementsCustomAdapter.AdapterListener {
CustomAdapter adapter;
@OverrideprotectedvoidonCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
adapter = newCustomAdapter();
adapter.setListener(this);
...
}
@OverridepublicvoidonDataListIsEmpty() {
// set visible or gone views
}
}
Post a Comment for "Hide Button If Not Data In Recyclerview"