gkpln3
gkpln3

Reputation: 1499

RecyclerView recognize when reaching end of scroll

I have a RecyclerView using a horizontal GridView with two scrolling buttons on the sides (the app is ment for cars running android so i had to add additional buttons in addition to the ability to scroll the view).

Now I want to be able to dim the buttons when I reach the end of the scrolling, not just the last item, but literaly when there is no more to scroll.

I wasn't able to find a good solution yet!

Upvotes: 1

Views: 4490

Answers (2)

Dor Rud
Dor Rud

Reputation: 114

Hello there add this to your code:

On your activity/fragment/where ever recyclerview is declared

RecyclerView rv; //Add your declare code (findViewById for example)
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (!recyclerView.canScrollHorizontally(1) ) {
        Toast.makeText(ChatDetailsActivity.this,"endOfScroll",Toast.LENGTH_LONG).show();
       //Implement button dim here. Example:
       //mybutton.setAlpha(0.5f);

    }
});

EDIT : Not sure if you want to scroll vertically or horizontally change the word from Horizontally to Vertically in the if statement acording your need

Upvotes: 3

Santanu Sur
Santanu Sur

Reputation: 11477

in onBind() of recyclerView adapter if (position==lastItem) { DisableButton.dimButon();} just add this ...and DisableButton is an Interface containing one method dimButon(); And in your activity make a field variable DisableButton dim; and in your onCreate intialize it using dim=new DisableButton(....

Upvotes: 0

Related Questions