Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

recyclerview snaphelper callbacks android

mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // specify an adapter (see also next example)
    mAdapter = new DemoSlidesAdapter(getApplicationContext());
    mRecyclerView.setAdapter(mAdapter);

    final SnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(mRecyclerView);

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if(newState == RecyclerView.SCROLL_STATE_IDLE) {
                View centerView = snapHelper.findSnapView(mLayoutManager);
                int pos = mLayoutManager.getPosition(centerView);
                Log.e("Snapped Item Position:",""+pos);
            }
        }
    });
Comment

PREVIOUS NEXT
Code Example
Java :: how to print a 2d array in java 
Java :: int array to set in java 
Java :: how to reverse order of arraylist 
Java :: java android play sound file with variable 
Java :: format localdatetime 
Java :: sieve of eratosthenes java 
Java :: set color of text for jlabel 
Java :: java create txt file 
Java :: Howow to use font object Java 
Java :: How do you print duplicate characters from a string? 
Java :: java get monitor size 
Java :: how to install java 11 jdk on ubuntu 20.04 
Java :: android up navigation 
Java :: array slice java 
Java :: java create date object from yesterday 
Java :: java robot left click 
Java :: finally block does not complete normallyJava(536871096) 
Java :: read file using scanner in java 
Java :: how to register event spiot 
Java :: difference between premitive and non-premitive 
Java :: how to cnahe chat format in bukkit 
Java :: decimal format 
Java :: java custom color 
Java :: Could not identify launch activity: Default Activity not found 
Java :: java last element of array 
Java :: open a new activity on click of a button 
Java :: java verify string is hexadecimal 
Java :: map java get first key 
Java :: java close tcp socket output stream but not socket 
Java :: add extension quarkus 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =