android


How do I detect when a specific item reaches top of a RecyclerView in Android?


I'm creating an app with a list of questions in a RecyclerView. In the same parent layout, I have a static TextView above the RecyclerView that displays instruction for a set of questions. What I want is to change the text in the TextView whenever a specific question reaches the top of the RecyclerView when scrolled. How can I accomplish this?
You would need to listen to the scrolling of your RecyclerView and get the first item displayed onto the screen.
Thanksfully, Android let us set a custom ScrollListener to a RecyclerView and with your LayoutManager you are able to know which item is shown first :
// initialize your RecyclerView and your LayoutManager
mLinearLayoutManager = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(mLinearLayoutManager);
// set a custom ScrollListner to your RecyclerView
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// Get the first visible item
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
//Now you can use this index to manipulate your TextView
}
});
EDIT : added Mateus Gondim clearance about the LayoutManager
You should override the default Recycler.OnScrollListener.
Have a look at this Code : https://gist.github.com/mipreamble/b6d4b3d65b0b4775a22e

Related Links

How to compute the rotation matrix as this result in Android opengl es?
How to use android camera2 api to record 60 fps video with fixed exposure time
After enabling webcam to emulator, my projects crash
Smack library warning
android - how to get the IP address of a BLE beacon device
after get an accesstoken ?in oauth
Show options spinner in action bar
Can't change target SDK in Android Studio
How to set font size in Android webView fixed , even if font size changed in Settings->Display->Font?
Azure Oauth authentication on embeded web browesers will be blocked on 20 April, 2017 warning came
Retrofit - Base URL is changed when request process is being executed
how to blur image in android and set it to relative layout
Xamarin.Android happens error on Android 7
Firebase database get children long value pass 0 to my class
EditText and Extra View on Android SoftKeyboard
Getting Black Screen when displaying Gallery picture into ImageView Android

Categories

HOME
sonarqube
fabricjs
cobalt
fuelux
c99
object
ns-3
case
swt
yahoo-finance
replace
jquery-ui
tvos
crystal-lang
pkcs#11
recordrtc
p2p
google-schemas
java.util.logging
resultset
x-cart
endpoint
onedrive-api
foreign-keys
drive
ksh
exit
beta
ckfinder
onload
custom-post-type
bulletphysics
carrierwave
postback
zend-debugger
r-grid
twos-complement
hibernate-search
indy10
xajax
reason
node-mssql
numberpicker
magento-1.9.3
automapper-5
user-defined-fields
tinymce-3
wpas
modelsim
boxing
backbone-collections
edit
git-flow
jqchart
otp
pdf-conversion
libjpeg
offline.js
rsa-archer-grc
testrail
reachability
builtins
reporting-services-2012
vulcanize
tooleap
cifilter
simevents
bizagi
kiosk
gocql
opserver
mod-proxy
uvc
viewer
cocos3d
human-computer-interface
mobility
lnk
paste
koala
mt4j
bin
gd-graph
sphinxql
inputmismatchexception
abstract-data-type
pyunit
josql
infobright
node-redis
expression-blend-4
event-receiver
http-daemon
instantiationexception
easyb
aspmenu
django-piston
data-mapping
mathematical-notation
pbcopy
pnrp

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