getActivity in Activity
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
I forgot to implements the recyclerclicklistener. After I implements the method and change getActivity to this it worked fine extends AppCompatActivity implements RecyclerItemClickListener.OnItemClickListener
You can pass parameters like this: mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, mRecyclerView)); Or for detail information you can refer this bolg :- Android - RecyclerView: Implementing single.
RecyclerView notifyItemChanged Prevent Scroll [duplicate]
Google Analytics doesn't report Real-time Android
Edit text integer
Titanium Alloy crash on android, Cannot call method 'open' of undefined
Native components, armeabi-v7a, and thumb?
Checkbox getting deselected in arrayadapter in listview
Android: member variable becoming null
How to detect color of the center of camera streaming in android without OpenCV
Missing App Icon after modifying Manifest
Save Image from res/drawable to Image Gallery Android
SQL lite select for actual week (from monday till sunday)
how to get imageview height and width after pinch zoom?
How to properly create a customized animated drawable?
Android Backstack Management
how to get mobile number from my current Phone? it's display blank Mobile Number in Log. but when run on emulator its display emulator Number [duplicate]
Is it possible to have different label name of launcher activity & application name