2016-07-13 54 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成員你不需要任何進口。