Reputation: 435
I have the following class:
public class MyFragment extends Fragment implements Observer<List<User>>
And
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {return false;}
@Override
public boolean onQueryTextChange(String searchText) {
if (searchText.length() > 0) {
myLiveData.removeObservers(getViewLifecycleOwner(), this);
}
return false;
}
});
To the removeObservers()
function I need to pass a LifecycleOwner
object as the first argument (which works) and as the second argument on Oberver
object. When using the above line of code, it fails because of the second this
is not referring the interface that is implemented in the fragment. How to make this
point to the right interface and get the corresponding Oberver
object?
Upvotes: 0
Views: 51