I am trying to create a ListActivity which its rows contain a text and an image. But It shows only one rows’ values the other rows’ images and texts are invisible. When I debug the code their values are not null. But it shows the rows but doesn’t show these text and image values on layout except the first row. Here is my code :
public class SutList extends ListActivity implements XmlListener,OnItemClickListener{
XMLParser xmlParser;
@SuppressWarnings("rawtypes")
ArrayList sutList = new ArrayList();
ProgressDialog sutProgress;
XmlObjectAdapter xmlObj;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
xmlParser = new XMLParser("http://192.168.2.101/eczaplus/AndroidAPI/search.php?searchtype=drug_sut&keyword="+SharedItems.getInstance().clickedObject.map.get("id"));
xmlParser.addMyEventListener(this);
xmlParser.startAsyncTask();
getListView().setOnItemClickListener(this);
}
@Override
public void xmlParsed(XmlEvent evt) {
sutList = evt.ownerClient.children;
xmlObj = new XmlObjectAdapter(this, R.layout.esdegerilac, sutList);
setListAdapter(xmlObj);
}
@Override
public void preExecute(EventObject evt) {
sutProgress = new ProgressDialog(SutList.this);
sutProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
sutProgress = ProgressDialog.show(SutList.this,"", "");
}
@Override
public void postExecute(EventObject evt) {
sutProgress.dismiss();
}
private class XmlObjectAdapter extends ArrayAdapter<XmlObject> {
private ArrayList<XmlObject> items;
public XmlObjectAdapter(Context context, int textViewResourceId, ArrayList<XmlObject> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.sutlist, null);
}
XmlObject o = items.get(position);
// System.out.println(o.map.get("name"));
if (o != null) {
TextView ilacText = (TextView) findViewById(R.id.sutNameText);
ImageView sutImage = (ImageView) findViewById(R.id.sutImage);
//HashMap< String, String> atr = (HashMap<String, String>) o.map;
if (sutImage != null){
if (o.map.get("exists").equals("1"))
sutImage.setImageResource(R.drawable.ok);
else
sutImage.setImageResource(R.drawable.not_ok);
if (ilacText != null)
ilacText.setText(o.map.get("title"));
}
}
return v;
}
}
Hope you can help me to figure out to solve this problem.
In your XmlObjectAdapter in getView() I believe you want
not just