2016-07-13 55 views
0

我已经实现了这个方法,就像许多其他教程所说的,但在我的情况下,编译器会引发错误。为什么?SCROLL_STATE_IDLE无法解析符号为什么?

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

    final RecyclerView recList = (RecyclerView) v.findViewById(R.id.ratingIconList); 
    recList.addOnScrollListener(new RecyclerView.OnScrollListener(){ 
        @Override 
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 
         super.onScrollStateChanged(recyclerView, newState); 

         if (newState == SCROLL_STATE_IDLE) { 
          MainActivity.programmaticScrollEnable = true; 
         } 
        } 

enter image description here

回答

0

由于要添加ScrollListener到ReciclerView,必须引用SCROLL_STATE_IDLE如下:

RecyclerView.SCROLL_STATE_IDLE 

SCROLL_STATE_IDLE可以因为你是在一个ListView做的前提下使用,你的OnScrollListener延伸AbsListView.OnScrollListener(这是不是你的案件)。

变化来自:

if (newState == SCROLL_STATE_IDLE) { 
    MainActivity.programmaticScrollEnable = true; 
} 

要:

if (newState == RecyclerView.SCROLL_STATE_IDLE) { 
    MainActivity.programmaticScrollEnable = true; 
} 

,因为这constast是已经被导入到你的项目的ReciclerView成员你不需要任何进口。