ANR更新viewPager时的Happend

时间:2018-02-02 09:47:44

标签: android android-viewpager android-handler

在尝试更新图像视图寻呼机时,我正在低于ANR。有没有人有想法?下面是我的代码。我怀疑当我执行setcurrentItem获取此ANR : Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 5.

private void setRelavantColourPic(ValueList valueList){
   if(valueList.getPictureId() != 0 && productImages != null && productImages.size() > 0){
       i = 0;

       for (ProductPictureList productPictureList : productImages ){
           int pictureId =  Integer.parseInt(productPictureList.getPictureId());
           i ++;
           if(pictureId == valueList.getPictureId()){
               foundIndex = i-1;
           }
       }



       mDelayHandler.postDelayed(
               mRunnable =   new Runnable() {
                   @Override
                   public void run() {
                       mProductImageViewPager.setCurrentItem(foundIndex);
                   }
               }, 1);
     //  mDelayHandler.post(mRunnable);

   }
}

1 个答案:

答案 0 :(得分:0)

我认为它正在递归并阻止主线程。请尝试删除以下声明,

mDelayHandler.post(mRunnable); 

它会起作用。