How to update first and second page view in view pager.?

≯℡__Kan透↙ 提交于 2020-01-06 19:49:05

问题


I have View-pager with nine images. I am setting images in view using bitmap. When i choose nine images from gallery first time, its show all nine images perfectly. Also when i choose another nine images from gallery with keep first first or second view same,view-pager display with updated images. But my problem is when I am trying to change all nine images with first and second. they display error like OutOfMemoryEror. so my question is. How to update first and second(next) view in view-pager. any one can help me.? than x in advance.

Activity code

if(ab != null){

      arr = ab.split(",");        

      for(int i = 0; i <arr.length; i++){                     
        //  Toast.makeText(getApplicationContext(), "done: "+ arr[i], Toast.LENGTH_LONG).show();

        imgFile = new  File(arr[i]);
        if(imgFile.exists()){
           myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());             

            System.out.println("This my - bit : "+myBitmap+"ara - lenth : "+arr.length);

            bitmapArray.add(myBitmap);

            System.out.println("This bit-aray : "+bitmapArray.size()+" : "+bitmapArray.size() + "ara pos : "+arr[i]);

      //Toast.makeText(getApplicationContext(), "This is bitmap array : "+ bitmapArray, Toast.LENGTH_LONG).show();           
        }

            }
    }else{

    }

Adapter code

if(l == 1){
//  layout.removeView(imageView); 
//  container.removeView(layout);
  if(bitmapArray != null){

     for(int j = 0; j < bitmapArray.size(); j++){

         if(j == position){

                j = position;
                imageView.setImageBitmap(bitmapArray.get(j));
            }
     }
     }   //Toast.makeText(getApplicationContext(), ""+bitmapArray.get(j)+"size "+bitmapArray.size(), Toast.LENGTH_SHORT).show();

 else{
     imageView.setImageResource(res[position]);
     bitarray.clear();
     bitmapArray.clear();
     sharedpreferences.edit().remove("imgpath").commit();
     }
   }
 if(l == 2){

//layout.removeView(imageView); 
//container.removeView(layout);

  if(bitmapArray != null){

         for(int j = 0; j < bitmapArray.size(); j++){

             if(j == position){

                    j = position;
                    imageView.setImageBitmap(bitmapArray.get(j));
                }
         }
         }   //Toast.makeText(getApplicationContext(), ""+bitmapArray.get(j)+"size "+bitmapArray.size(), Toast.LENGTH_SHORT).show();

     else{
         imageView.setImageResource(res[position]);
         bitarray.clear();
         bitmapArray.clear();
         sharedpreferences.edit().remove("imgpath").commit();
     }

 }

来源:https://stackoverflow.com/questions/30961325/how-to-update-first-and-second-page-view-in-view-pager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!