Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay Image in a Listview (In Adapter) using Json
    text
    copied!<p>Please bear with me before downvoting this.I am a beginner to Android. After trying multiple solutions on here I have failed to resolve this.</p> <p>I am trying to set the Image in the listview with the following items in place.I want to be able to insert the image code somewhere on the Schedule adapter class.</p> <p>The following code is my Schedule Adapter </p> <pre><code>public class Schedule_ArrayAdapter extends ArrayAdapter&lt;String&gt; { private final Activity activity; private final String[] name, category, image; Typeface colab, colab_bold, Bebas; int selected = -1; public Schedule_ArrayAdapter(Activity activity, String[] name, String[] category, String[] image) { super(activity, R.layout.schedule_item, category); this.activity = activity; this.name = name; this.category = category; this.image = image; this.colab = Typeface.createFromAsset(activity.getAssets(), "ColabThi.otf"); this.colab_bold = Typeface.createFromAsset(activity.getAssets(), "ColabMed.otf"); this.colab_bold = Typeface.createFromAsset(activity.getAssets(), "BebasNeue.otf"); } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); //get view and textview from xml View rowView = inflater.inflate(R.layout.schedule_item, parent, false); rowView.setBackgroundColor(0xffffffff); LinearLayout background = (LinearLayout) rowView.findViewById(R.id.back); if (selected != -1) { if (selected == position) { background.setBackgroundColor(0xffeaac4b); } else { background.setBackgroundColor(0xffffffff); } }else{ background.setBackgroundColor(0xffffffff); } TextView TimeView = (TextView) rowView.findViewById(R.id.category); TextView TitleView = (TextView) rowView.findViewById(R.id.title); ImageView vi = (ImageView) rowView.findViewById(R.id.imgPreview); GetImage getimage = new GetImage(); getimage.execute(image); //change names TitleView.setText(category[position]); TitleView.setTextSize(fontpercent_screenheight(3.5)); TitleView.setPadding(dp(10), dp(5), dp(5), dp(0)); TitleView.setTypeface(Bebas); TimeView.setText(name[position]); TimeView.setTextSize(fontpercent_screenheight(3.5)); TimeView.setPadding(dp(10), dp(2), dp(5), dp(5)); TimeView.setTypeface(colab); return rowView; } </code></pre> <p>The following is my ImageDownloader class</p> <pre><code>public class ImageDownloader { private InputStream OpenHttpConnection(String image) throws IOException { InputStream in = null; int response = -1; URL url = new URL(image); URLConnection conn = url.openConnection(); if (!(conn instanceof HttpURLConnection)) throw new IOException("Not an HTTP connection"); conn.setUseCaches(true); HttpURLConnection httpConn = (HttpURLConnection) conn; try { httpConn.setAllowUserInteraction(false); httpConn.setInstanceFollowRedirects(true); httpConn.setRequestMethod("GET"); httpConn.connect(); response = httpConn.getResponseCode(); if (response == HttpURLConnection.HTTP_OK) { in = httpConn.getInputStream(); } } catch (Exception ex) { throw new IOException("Error connecting" + ex); } return in; } public Bitmap DownloadImage(String image) { Bitmap bitmap = null; InputStream in = null; try { in = OpenHttpConnection(image); bitmap = BitmapFactory.decodeStream(in); in.close(); } catch (IOException e1) { e1.printStackTrace(); } return bitmap; } } </code></pre> <p>Parsing of JSON and fetching Data is working as normal. When looking in the debugger the "image" array is also been fetched. How do i set the images in the view ? <img src="https://i.stack.imgur.com/nlvg7.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload