Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid | ListView Using Layoutinflater
    text
    copied!<p>Im Writing An Application that reads XML file and Displays it as a ListView cause each row has its own Image and Text i am using LayoutInflater, i can display the Texts but cant display Images! this is the code i use for ImageAdapter:</p> <pre><code>public class ImageAdaptertwo extends ArrayAdapter&lt;String&gt; { private final Context context; private final ArrayList&lt;String&gt; values; private final ArrayList&lt;String&gt; values2; public ImageAdaptertwo(Context context, ArrayList&lt;String&gt; values,ArrayList&lt;String&gt; values2) { super(context, R.layout.trimester1_listview, values); this.context = context; this.values = values; this.values2 = values2; } @Override public View getView(int position, View convertView, ViewGroup parent) { String s = values.get(position); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.trimester1_main, parent, false); TextView textView = (TextView) rowView.findViewById(R.id.label2); ImageView imageView = (ImageView) rowView.findViewById(R.id.icon2); textView.setText(values2.get(position)); // Change icon based on name //String s = values.get(position); System.out.println(s); if (s.equals(" havingsuccessful-pregnancyS.png")) { imageView.setImageResource(R.drawable.n1); } else if (s.equals("urfoodguideduringpregnancyS.png")) { imageView.setImageResource(R.drawable.n2); } else if (s.equals("lovingurpregnantbodyS.png")) { imageView.setImageResource(R.drawable.n3); } else if (s.equals("gettinggoodbreastafterS.png")) { imageView.setImageResource(R.drawable.n4); } else if (s.equals("FoodGuidePyramidS.png")) { imageView.setImageResource(R.drawable.n5); } else if (s.equals("pregnancyS.png")) { imageView.setImageResource(R.drawable.n6); } else if (s.equals("nutritionfoS.png")) { imageView.setImageResource(R.drawable.n7); } else if (s.equals("Your-Growing-ChildS.png")) { imageView.setImageResource(R.drawable.n8); } else if (s.equals("Fatigue-in-first-trimesterS.png")) { imageView.setImageResource(R.drawable.n9); } else if (s.equals("T1S.png")) { imageView.setImageResource(R.drawable.n10); } return rowView; } } </code></pre> <p>values and values2 are the ArrayList which are Coming from XML Parser! Actually no they are ok because i print the content of them and see them in LogCat! in my Activit i use this for Adapting ImageAdapter</p> <pre><code>setListAdapter(new ImageAdaptertwo(this, imagelink,texts)); </code></pre> <p>The result is a listview with texts but no Images! can anybody tell me how i can fix this and display XML contents on ListView? </p> <p>Solved the problem by changing if Statements to Switch Case . now for each row i have specific number</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