0

I need to change the visibility of a button deppending on a recycler's view content, when it changes it must become visible otherwise it has to remain invisible

I've tried with interfaces, callback and "onactivityresult" to add a changelistener to the recyclerview, with the interface I can access a method from the parent class but I cant reach the view's it returns me nulls

the structure is the following:

parent class(viewpager, with button that needs to change it's visibility) child class(recyclerview) adapter(Call to API service, listener to button and Edittext, "I need to modify it from here")

1 Answer 1

0

Here are the steps if you want to send data from child class to parent class.

You have to create a custom listener.

public interface HideButton{
  void hideButton();
}

now create a instance of this interface in child class or adapter class

HideButton hideButtonListener;

and create a setter in the adapter class,

public void setButtonHideListener(HideButton listener){
     this.hideButtonListener = listener;
}

and call this setter from parent class by the adapter reference e.g

adapter.setButtonHideListener(new HideButton(){
    void hideButton(){
    //here you change the visibility of the button in parent class
    }
});

one more step. Now when you call an api in adapter and receive the response, you call this code

if(hideButtonListener != null){
   hideButtonListener.hideButton();
}
1
  • Now parent will listen on this listener, whenever the child class calls it. parent will receive it and you can perform your action. e.g hide button or show button. etc.. Commented Jun 19, 2019 at 14:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.