mRecycle.setOnScrollListener (new new RecyclerView.OnScrollListener () {
@Override
public void onScrolled (RecyclerView recyclerView, DX int, int Dy) {
super.onScrolled (recyclerView, DX, Dy);
}
@Override
public void onScrollStateChanged (RecyclerView recyclerView, int newState The ) {
super.onScrollStateChanged (recyclerView, newState the);
RecyclerView.LayoutManager layoutManager recyclerView.getLayoutManager = ();
// determines whether the current layoutManager LinearLayoutManager
// LinearLayoutManager have only to find the first and last visible view location method
IF (layoutManager the instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
// Get the last visible view position
int lastItemPosition linearManager.findLastVisibleItemPosition = ();
// get the first view a visible position
int firstItemPosition = linearManager.findFirstVisibleItemPosition ( );
IF (foodsArrayList.get (firstItemPosition) the instanceof Foods) {
int foodTypePosion = ((Foods) foodsArrayList.get (firstItemPosition)) getFood_stc_posion ().;
FoodsTypeListview.getChildAt(foodTypePosion).setBackgroundResource(R.drawable.choose_item_selected);
}
System.out.println(lastItemPosition + " " + firstItemPosition);
}
}
});
@Override
public void onScrolled (RecyclerView recyclerView, DX int, int Dy) {
super.onScrolled (recyclerView, DX, Dy);
}
@Override
public void onScrollStateChanged (RecyclerView recyclerView, int newState The ) {
super.onScrollStateChanged (recyclerView, newState the);
RecyclerView.LayoutManager layoutManager recyclerView.getLayoutManager = ();
// determines whether the current layoutManager LinearLayoutManager
// LinearLayoutManager have only to find the first and last visible view location method
IF (layoutManager the instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
// Get the last visible view position
int lastItemPosition linearManager.findLastVisibleItemPosition = ();
// get the first view a visible position
int firstItemPosition = linearManager.findFirstVisibleItemPosition ( );
IF (foodsArrayList.get (firstItemPosition) the instanceof Foods) {
int foodTypePosion = ((Foods) foodsArrayList.get (firstItemPosition)) getFood_stc_posion ().;
FoodsTypeListview.getChildAt(foodTypePosion).setBackgroundResource(R.drawable.choose_item_selected);
}
System.out.println(lastItemPosition + " " + firstItemPosition);
}
}
});