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.
Fragment getView().findViewById(R.id.box1) Returning null
How to add new Cordova lifecycle events?
Adding random number of buttons dynamically and setting onClickListener in Android
How do I use a third party Handwriting application as input to a web database?
Screenshots are not uploading on Play Store
Getting contact's birthday error
Android QuickBlox - User must have a list of contacts
Add multiple views in ScrollView?
How to send update SQLite table from one to everyother
Android Google Maps LocationClient
Foreground service that stops running
Javac doesn't create native .c file from .java. JNI
Text field from a ListView
Android SQLite best practice for memory performance
SQLiteDatabase.loadLibs Fatal signal 11 when using x86 native library
ffmpeg Build Output is not showing?