I have implemented a ricyvlerview search, and i want to listen for clicks, but context is allways null, i even tryed to move the method to an activity and i got the same result
This is my first time messing arround with Data binding i searched alot here but i can't find what i am doing wrong
item_exemple.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
    <variable
        name="model"
        type="pt.condutorresponsavel.android.testescodigo.Search.models.ExampleModel"/>
    <variable
        name="handlers"
        type="pt.condutorresponsavel.android.testescodigo.Study"/>
</data>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    android:clickable="true">
    <TextView
        android:onClick="@{(v) -> handlers.onCategoryClick(v,model)}"
        android:ellipsize="end"
        android:lines="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:text="@{model.text}"/>
    <View
        android:layout_marginTop="40dp"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@color/colorPrimary"
        android:alpha="0.17"/>
</FrameLayout>
ExampleViewHolder.java
public class ExampleViewHolder extends SortedListAdapter.ViewHolder<ExampleModel> {
private final ItemExampleBinding mBinding;
public ExampleViewHolder(ItemExampleBinding binding) {
    super(binding.getRoot());
    mBinding = binding;
}
@Override
protected void performBind(ExampleModel item) {
    mBinding.setModel(item);
    mBinding.setHandlers(new Study());
}
}
Study.java
public class Study extends Fragment {
public static Fragment fragment;
public static SearchView searchView;
Context context;
private final String[] pageNames = {"Favorites", ""};
ViewPager pager;
private OnFragmentInteractionListener mListener;
public Study() {  }
public static Estudo newInstance(String param1, String param2) {
    Estudo fragment = new Estudo();
    Bundle args = new Bundle();
    fragment.setArguments(args);
    return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_estudo, container, false);
    fragment = this;
  ...
    pager = (ViewPager) view.findViewById(R.id.pager);
    pager.setAdapter(buildAdapter());
    return view;
}
private PagerAdapter buildAdapter() {
    return(new SampleAdapter(getActivity(), getChildFragmentManager()));
}
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    this.context = context;
}
public interface OnFragmentInteractionListener {
    void onFragmentInteraction(Uri uri);
}
public class SampleAdapter extends FragmentPagerAdapter {
    Context ctxt = null;
    public SampleAdapter(Context ctxt, FragmentManager mgr) {
        super(mgr);
        this.ctxt = ctxt;
    }
    @Override
    public int getCount() {
        return (2);
    }
    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return Favorites.newInstance(position + 1);
        }else{
            return otherFragment.newInstance(position + 1);
        }
    }
        @Override
        public String getPageTitle ( int position){
            return (String.valueOf(pageNames[position]));
        }
}
public void onCategoryClick(View view, ExampleModel model) {
    Log.d("mTag", "Index: " + model.getId());
    Dialog dialog = new Dialog(getActivity()); //NullPointerException
    dialog.setContentView(R.layout.dialog_pergunta);
    dialog.show();
}
public static class Favorites extends Fragment{...} //RecyclerView is in here
public static class otherFragment extends Fragment{...}
}
Problem
public void onCategoryClick(View view, ExampleModel model) {
Log.d("mTag", "Index: " + model.getId());
Dialog dialog = new Dialog(getActivity()); //NullPointerException
dialog.setContentView(R.layout.dialog);
dialog.show();
}
i tried setting the context in onAttach and also tried to use
final Context contex = getActivity();
but nothing worked outside onCategoryClick the context is not null but inside onCategoryClick the context is null
how can i overcome this?
EDIT
if i don't declare my interface static i get this
NullPointerException: Attempt to invoke interface method 'void pt.condutorresponsavel.android.testescodigo.Study$OnItemClick.onClick(long)' on a null object reference at
pt.condutorresponsavel.android.testescodigo.Study.onCategoryClick(Study.java:303)
