I'm having trouble with getActivity() in Activity. It says can't resolve method getActivity(). I'm using it to make onClick in recyclerView.
Here is my code
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), this));
What should I change getActivity with? Thanks in advance
You have declared your code inside of an Activity. Therefore you can simply use this to reference the Activity you are in.
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, this));
change it to
this
this is a reference to the class your in, like MainActivity.this
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