android


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.

Related Links

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?

Categories

HOME
android
google-cloud-platform
oracle12c
apache-flink
wakanda
dns
fpga
github-for-windows
mjml
static
soa
title
endeca
mautic
line
pybossa
bitnami
altera
searchview
red5
delphi-xe5
dpdk
backpack-for-laravel
ember-cli
postscript
aggregation
resourcebundle
dapper-extensions
windows-server-2003
slidetoggle
linked-data
intersystems-cache
soot
twiml
dst
mockjax
left-join
jmockit
contacts
nohup
kill
odoo-website
chronicle-map
memory-mapping
uiimage
proget
magento-2.0.7
context-sensitive-grammar
yii2-user
ngmaterial
er-diagram
gpg-signature
template-toolkit
shinobi
sandcastle
rmongo
simplepie
seek
flex4.6
scaffolding
cassia
php-socket
html-to-pdf
invoke-sqlcmd
kendo-upload
sapi
file-move
wiredep
oracle-spatial
lazybones
xvim
dock
finalbuilder
teamcity-9.1
node-serialport
user-permissions
java-security
android-cookiemanager
viewer
ghcjs
administration
universal-image-loader
build-script
twitter-bootstrap-rails
conditionaltagsupport
sbcl
multitasking
ie8-compatibility-mode
code-duplication
rolify
tlf
epiceditor
argouml
veracity
zope.interface
os.system
correlated-subquery
cuda-gdb
jdb
multiplexing
fitbounds
google-maps-mobile
google-floodlight
appledoc
tui
fail-fast-fail-early
software-lifecycle
httpcookie
leader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App