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

Can you detect when Android App goes into background? [duplicate]
Streching two layouts in parent layout
How can I have both a return and a done keys in an EditText's softkeyboard?
convert touched value to points based on matrix
Creating internal file in android
Download packages of assets in phonegap
Timing issues with the GPS
Is this is OK to use the ListView for inline editing?
Partial wake lock is not working
Stuck while installing sample helloAndroid application in emulator
How to make words in checkbox text to be link
About connecting web database with Android application
can we make the whole application zoomable in android ?
Getting issue to set the color on list view item
Android - Is it possible to have dynamically moving clickable objects in a view
Make ball bounce and eventually come to rest

Categories

HOME
sonarqube
phantom-dsl
developer-tools
merge
interface
themes
pascal
database-normalization
xbee
scripting
parameters
settings
x264
fosrestbundle
google-chrome-app
endeca
windows-ce
naivebayes
code-generation
qsqlquery
powershell-v5.0
html5-appcache
visual-glitch
imagemap
r-mice
roslyn
exit
tosca
roundup
windows-server-2003
xcode-ui-testing
definitelytyped
itunes
angular-translate
weather
papaparse
linkedhashmap
gojs
slacktextviewcontroller
android-augmented-reality
preloader
congestion-control
strftime
opennms
chai-as-promised
avx
google-photos
visual-studio-2008-sp1
cudd
expectations
refinerycms
grass
aspen
highland.js
relativelayout
gocql
iokit
coda
jdk1.7
wso2greg
dot.js
theos
uncaught-typeerror
mruby
jqmodal
rcaller
matrix-inverse
menubar
artemis
breakout
inputmismatchexception
windows-phone-8-sdk
asdf
nevron
process-explorer
actiondispatch
cgimage
hibernateexception
luabind
winmain
drawtobitmap
mbeans
collectionviewsource
svk
non-clustered-index
jqueryform
eclipse-marketplace
message-passing
qtabbar
wordprocessingml

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