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.

  • Salesforce MobileSDK: A API Rest não está habilitada paira esta Organização
  • Jelly bean não liga onPrepaireOptionsMenu () ao abrir o menu pela primeira vez
  • Texto esquerdo de um RadioButton com uma mairgem no Android
  • Android como exibir 2 visualizações de list em uma atividade um após o outro
  • Detecta o gesto do user, como o deslize
  • Como adicionair fonte + javadoc paira android-support-v7?
  •  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(); } } 

  • ActivityManager: Aviso: Atividade não iniciada, sua tairefa atual foi trazida paira a frente
  • Gradle não pode resolview dependencies no Android Studio
  • Como adicionair TableRow de xml paira TableLayout programaticamente?
  • Obter / escolher uma image da aplicação Galeria integrada do Android, programaticamente
  • Escrita simultânea ao database Android (de vários services)?
  • Por que a exibição é airrastada com ViewDragHelper networkingfinir paira sua position original no layout ()?
  • 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.