I use the following code to display a remote image with the next and previous buttons. By pressing the next and previous buttons two or three times, the image will not be displayed as follows. and the DisplayLiveImage bitmap is null.
Can anyone check this is a buffer problem? or connection?
ImageView img; int CurrentImageIndex; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.imageviwer); setTitle("some text"); myRemoteImages = new String[6]; myRemoteImages[0]="http://www.comparecheapinsurance.com/car-insurance/images/car-insurance-policy.jpg"; myRemoteImages[1]="http://www.speedace.info/solar_cars/solar_car_images/auburn_university_solar_car_banked_road_test.jpg"; myRemoteImages[2]="http://zedomax.com/blog/wp-content/uploads/2009/07/car.jpg"; myRemoteImages[3]="http://www.wallpaperez.net/wallpaper/car/Lamborghini-prototype-car-926.jpg"; myRemoteImages[4]="http://www.evbeat.com/blog/wp-content/uploads/2009/03/aptera-electric-car.jpg"; myRemoteImages[5]="http://www.cartuningcentral.com/wp-content/uploads/2008/01/exotic-car-pagani-zonda.jpg"; CurrentImageIndex= 0; img= (ImageView)findViewById(R.id.myImageView); DisplayLiveImage(CurrentImageIndex); Button previous = (Button)findViewById(R.id.btnPrevious); Button next = (Button)findViewById(R.id.btnNext); next.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { ShowNext(); } }); previous.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { ShowPrevious(); } }); } public void DisplayLiveImage(int val) { try { URL aURL = new URL(myRemoteImages[val]); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); Bitmap bm = BitmapFactory.decodeStream(bis); bis.close(); is.close();
any help would be assigned.
Umar
source share