If you are using a local image, use RemoteViews.setImageViewUri .
String url = new File(mWidgetItems.get(position).getCoverImageUrl()).toString(); rv.setImageViewUri(R.id.timelineCellImage, Uri.parse(url));
If you are using a network resource, use RemoteViews.setImageViewBitmap .
Bitmap bm = getImageBitmap(mWidgetItems.get(position).getCoverImageUrl()); rv.setImageViewBitmap(R.id.timelineCellImage, bm); // Helper method to get Image bitmap private Bitmap getImageBitmap(String purl) { Bitmap bm = null; try { URL url = new URL(purl); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.connect(); try { InputStream in = new BufferedInputStream( urlConnection.getInputStream() ); bm = BitmapFactory.decodeStream(in); } finally { urlConnection.disconnect(); } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bm; }
Remove the clickable and onClick from ImageView . The onClick attribute adds a setOnClickListener . You can refer to this answer that I wrote earlier. If you want to handle the click event on ImageView in case of remote views, you should use RemoteViews.setOnClickPendingIntent .
source share