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

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

Categories

HOME
url-redirection
hyperlink
gdb
sitecore
solaris
error-handling
appcelerator
google-apps
boto3
gkturnbasedmatch
onedrive-api
3nf
linear-algebra
azure-iot-hub
firefox-addon
wolframalpha
soci
symfony-console
sigma.js
hta
aggregation
direct3d11
beautifier
slidetoggle
pic32
8051
android-things
tizen-tv
winpe
gitlab-api
record
cognos-bi
mailkit
browser-extension
mnist
video-capture
xajax
tex
flatmap
nohup
metaprogramming
apache-stanbol
laravel-elixir
softmax
phpdbg
linter
clarifai
dotnet-httpclient
spring-integration-sftp
dtsearch
yii2-user
backbone-collections
type-theory
flyout
cmp
javafx-css
pocketsphinx-android
juice-ui
stripe-connect
pacemaker
iotivity
spring-cloud-feign
file-uri
resourcemanager
beamer
rspec2
hclust
delta
project-organization
cda
false-sharing
inf
boomerang
decimalformat
lazybones
forwarding
dock
vacuum
osc
fits
zxspectrum
bcache
code-documentation
infosphere-spl
delayed-execution
iiop
sonarqube-5.0
device-tree
ss7
kissfft
grails-domain-class
websphere-esb
light
inappsettingskit
nebula
resource-management
intersect
pstack
webdev.webserver
creole
w3c-geolocation
inline-formset
cloudfiles
objective-j
easyb
perl5.12

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