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

How to store all unread notification in android?
remove gap from android-gallery
Android FTPClient code is not uploading file from sdcard to FTP server
GPS app - Runs but shuts down on button click
WiFi Connection in Multiplayer Android Game
How to create a method for saving a file and returning it as object ready for editing Android
No empty constructor can't initiate class
How to use reflection to access secure element
Kivy: How to call something on button on_press
Reading RAW resources and saving into Internal storage
Infinite loop when attemping to check if user is signed in. google +
getting formated IP adress of own device android [duplicate]
Android layout design..adjust on heading
How to parse contents in zxing barcode library in android
Move Background Screen in libgdx game(android)
Andorid How to get the name of the current city using coordinates

Categories

HOME
scikit-learn
twitter-bootstrap-3
cobalt
cheerio
formal-languages
graphics
appcelerator
edge
newrelic
alsa
tvos
python-multithreading
sendgrid-api-v3
arangodb
google-schemas
commonjs
heap
gson
distribution
mod-security
ycsb
google-form
endpoint
onedrive-api
symmetricds
android-7.0-nougat
digital-signature
symfony-console
apache2.4
breadth-first-search
href
gulp-watch
php-mysqlidb
onload
itunes
syntax-highlighting
genexus-sd
tpm
tizen-tv
vex
corenlp-server
scatter3d
testbed
erb
openwhisk
joomla2.5
html-encode
sql-server-ce
xcode7.3
ideascript
news
kill
visa
datacachefactory
placeholder
pom.xml
yii2-api
launchctl
x-ray
podscms
zenhub
stdmap
compiler-design
bbpress
css-transforms
reshape
pybrain
javafx-css
change-tracking
simplepie
resourcemanager
watch-os-2
macaulay2
firebase-security
fink
database-relations
libav
thread-sleep
grass
kendo-upload
rasterize
jnlua
computer-architecture
keyup
teamcity-9.1
actionfilterattribute
cross-join
exceldatareader
contrast
iso-prolog
webfinger
ignite-ui
cfcache
xmltodict
dtmf
workitem
kaleidoscope
video-codecs
superscrollorama
pdfviewer
veracity
objectquery
appjs
httponly
window-decoration
virtualpathprovider
google-maps-mobile
flex-mobile
screen-size
uipagecontrol
xui
interprocess
pos-for-.net
purepdf
linfu-dynamicproxy
flvplayback
mathematical-typesetting

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