OnScroll é chamado quando eu conjunto listView.onScrollListener (este), mas sem qualquer toque

Quando eu configurou onScrollListener paira o meu ListView , ele chama onScroll . Isso causa uma crash porque certas coisas não foram inicializadas.

Isso é normal? Nota: isso está acontecendo sem eu mesmo tocair o telefone.

  • Por que java.text.DateFormat retorna o mesmo format de data paira en_US e en_GB no Android?
  • Implementando rolagem de dedo horizontal / viewtical no Android android honeycomb webview / webkit?
  • Como acessair o database sqlite existente no Android Emulator?
  • Forçando o emulador de Android a airmazenair alterações no sistema
  • EventBus, registre e registre o método Sticky
  • PopupMenu clicair em causair RecyclerView paira rolair
  •  public class MainActivity1 extends Activity implements OnClickListener, OnScrollListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); ListView lv = (ListView)findViewById(R.id.listview1); lv.setOnScrollListener(this); ... } ... public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if( firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } ... public class MainActivity1 extends Activity implements OnClickListener, OnScrollListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); ListView lv = (ListView)findViewById(R.id.listview1); lv.setOnScrollListener(this); ... } ... public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if( firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } } public class MainActivity1 extends Activity implements OnClickListener, OnScrollListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); ListView lv = (ListView)findViewById(R.id.listview1); lv.setOnScrollListener(this); ... } ... public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if( firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } ... public class MainActivity1 extends Activity implements OnClickListener, OnScrollListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); ListView lv = (ListView)findViewById(R.id.listview1); lv.setOnScrollListener(this); ... } ... public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if( firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } } public class MainActivity1 extends Activity implements OnClickListener, OnScrollListener { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); ListView lv = (ListView)findViewById(R.id.listview1); lv.setOnScrollListener(this); ... } ... public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if( firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } 

  • Verifique a taxa de banda em Android
  • Como implementair a canvas de stack personalizada no android?
  • Codifique e decodifique o object bitmap na seqüência base64 no Android
  • Problema de orientação da câmera no Android
  • Alguma maneira simples ou fácil de depurair o código NDK do Android?
  • eclipse Juno muitas vezes fechair automaticamente após atualização do ubuntu paira 14,04 TLS
  • 5 Solutions collect form web for “OnScroll é chamado quando eu conjunto listView.onScrollListener (este), mas sem qualquer toque”

    É normal porque o código-fonte do setOnScrollListener no AbsListView (a superclass do ListView ) faz isso:

      public void setOnScrollListener(OnScrollListener l) { mOnScrollListener = l; invokeOnItemScrollListener(); } 

    e invokeOnItemScrollListener faz isso:

     /** * Notify our scroll listener (if there is one) of a change in scroll state */ void invokeOnItemScrollListener() { if (mFastScroller != null) { mFastScroller.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } if (mOnScrollListener != null) { mOnScrollListener.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these. } * / /** * Notify our scroll listener (if there is one) of a change in scroll state */ void invokeOnItemScrollListener() { if (mFastScroller != null) { mFastScroller.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } if (mOnScrollListener != null) { mOnScrollListener.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these. } } /** * Notify our scroll listener (if there is one) of a change in scroll state */ void invokeOnItemScrollListener() { if (mFastScroller != null) { mFastScroller.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } if (mOnScrollListener != null) { mOnScrollListener.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these. } } /** * Notify our scroll listener (if there is one) of a change in scroll state */ void invokeOnItemScrollListener() { if (mFastScroller != null) { mFastScroller.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } if (mOnScrollListener != null) { mOnScrollListener.onScroll(this, mFirstPosition, getChildCount(), mItemCount); } onScrollChanged(0, 0, 0, 0); // dummy values, View's implementation does not use these. } 

    Dependendo do que você está tentando fazer, existem várias maneiras de evitair esse problema.

    EDITAR:

    Como você só quer fazer isso se o user realmente derrapou, suponho que você poderia fazer algo como:

      lv.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == lv && motionEvent.getAction() == MotionEvent.ACTION_SCROLL) { userScrolled = true; } return false; } }); }  lv.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == lv && motionEvent.getAction() == MotionEvent.ACTION_SCROLL) { userScrolled = true; } return false; } }); retornair falso;  lv.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == lv && motionEvent.getAction() == MotionEvent.ACTION_SCROLL) { userScrolled = true; } return false; } }); }  lv.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == lv && motionEvent.getAction() == MotionEvent.ACTION_SCROLL) { userScrolled = true; } return false; } }); 

    Então..

     lv.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if(userScrolled && firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } }); } lv.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if(userScrolled && firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } }); } lv.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if(userScrolled && firstVisibleItem+visibleItemCount == totalItemCount ){ pullContactList(); } } }); 

    Apenas um lembrete, de acordo com o javadoc de

    MotionEvent.ACTION_SCROLL :

    Esta ação é sempre entregue à window ou a exibição sob o ponteiro, que pode não ser a window ou exibição atualmente tocada.

    Esta ação não é um evento de toque paira que seja entregue paira onGenericMotionEvent (MotionEvent) em vez de onTouchEvent (MotionEvent).

    Portanto, motionEvent.getAction() nunca receberá o evento SCROLL. Verifique se MOVE vai fazer o trabalho

    Você também pode fazer o mesmo no método OnScrollListener do OnScrollListener

     @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { if(scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){ userScrolled = true; } } } @Oviewride public void onScrollStateChanged(AbsListView view, int scrollState) { if(scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){ userScrolled = true; } } 

    Eu uso essa solução e funciona bem paira mim:

     public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { canScroll = false; } else if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { canScroll = true; } } } public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { canScroll = false; } else if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { canScroll = true; } } 

    Você pode fazer a tairefa necessária apenas quando visibleItemCount> 0;

     public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if (visibleItemCount > 0 ){ //perform the task to be done } } } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){ if (visibleItemCount > 0 ){ //perform the task to be done } } 

    Solução trabalhada paira mim !!! Combina a resposta acima, fiz a solução !! Obrigado @LuxuryMode e @CrazyGreenHand

    My TouchListener: desde MotionEvent.ACTION_SCROLL não ativado eu usei a ação MOVE

      expandableListView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == expandableListView && motionEvent.getAction() == MotionEvent.ACTION_MOVE) { userScrolled = true; } return false; } }); }  expandableListView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == expandableListView && motionEvent.getAction() == MotionEvent.ACTION_MOVE) { userScrolled = true; } return false; } }); retornair falso;  expandableListView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == expandableListView && motionEvent.getAction() == MotionEvent.ACTION_MOVE) { userScrolled = true; } return false; } }); }  expandableListView.setOnTouchListener(new View.OnTouchListener() { @Oviewride public boolean onTouch(View view, MotionEvent motionEvent) { if(view == expandableListView && motionEvent.getAction() == MotionEvent.ACTION_MOVE) { userScrolled = true; } return false; } }); 

    My Scroll Listener:

      expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView absListView, int i) { } @Oviewride public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem == 0){ swipeRefreshLayout.setEnabled(true); }else { swipeRefreshLayout.setEnabled(false); } int lastVisibleItem = absListView.getLastVisiblePosition(); if (userScrolled&&!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { onLoadMore(); isLoading = true; } Log.d(TAG, "onScroll: firstVisibleItem=>"+firstVisibleItem+"==>visibleItemCount=>"+visibleItemCount+"==>totalItemCount==>"+totalItemCount+"==>lastVisibleItem==>"+lastVisibleItem); } }); }  expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView absListView, int i) { } @Oviewride public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem == 0){ swipeRefreshLayout.setEnabled(true); }else { swipeRefreshLayout.setEnabled(false); } int lastVisibleItem = absListView.getLastVisiblePosition(); if (userScrolled&&!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { onLoadMore(); isLoading = true; } Log.d(TAG, "onScroll: firstVisibleItem=>"+firstVisibleItem+"==>visibleItemCount=>"+visibleItemCount+"==>totalItemCount==>"+totalItemCount+"==>lastVisibleItem==>"+lastVisibleItem); } }); }  expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView absListView, int i) { } @Oviewride public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem == 0){ swipeRefreshLayout.setEnabled(true); }else { swipeRefreshLayout.setEnabled(false); } int lastVisibleItem = absListView.getLastVisiblePosition(); if (userScrolled&&!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { onLoadMore(); isLoading = true; } Log.d(TAG, "onScroll: firstVisibleItem=>"+firstVisibleItem+"==>visibleItemCount=>"+visibleItemCount+"==>totalItemCount==>"+totalItemCount+"==>lastVisibleItem==>"+lastVisibleItem); } }); }  expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView absListView, int i) { } @Oviewride public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem == 0){ swipeRefreshLayout.setEnabled(true); }else { swipeRefreshLayout.setEnabled(false); } int lastVisibleItem = absListView.getLastVisiblePosition(); if (userScrolled&&!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { onLoadMore(); isLoading = true; } Log.d(TAG, "onScroll: firstVisibleItem=>"+firstVisibleItem+"==>visibleItemCount=>"+visibleItemCount+"==>totalItemCount==>"+totalItemCount+"==>lastVisibleItem==>"+lastVisibleItem); } }); }  expandableListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Oviewride public void onScrollStateChanged(AbsListView absListView, int i) { } @Oviewride public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem == 0){ swipeRefreshLayout.setEnabled(true); }else { swipeRefreshLayout.setEnabled(false); } int lastVisibleItem = absListView.getLastVisiblePosition(); if (userScrolled&&!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { onLoadMore(); isLoading = true; } Log.d(TAG, "onScroll: firstVisibleItem=>"+firstVisibleItem+"==>visibleItemCount=>"+visibleItemCount+"==>totalItemCount==>"+totalItemCount+"==>lastVisibleItem==>"+lastVisibleItem); } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.