I am populating the list view with data I am getting from a JSON Array.The meta data that I am getting is being duplicated when I scroll on the list view.
public View getView(int pos, View convertView, ViewGroup parent) {
View tv;
TextView t;
if (convertView == null)
tv = m_inflater.inflate (R.layout.item, parent, false);
else
tv = convertView;
try {
t = (TextView) tv.findViewById(R.id.text);
JSONObject obj = _results.getJSONObject(pos);
t.setText (obj.getString("title").replaceAll("\\<.*?\\>", ""));
t = (TextView) tv.findViewById(R.id.created_at);
JSONObject meta = obj.getJSONObject("meta");
t.setText (t.getText() + "\n"+ "When:" + "\t"+meta.getString("startDate")+"\n"+"Location:" +"\t" +meta.getString("location")+"\n" +"More Info:"+"\t" +meta.getString("eventURL")+"\n");
} catch (JSONException e) {
Log.e("alatta", e.getMessage());
}
return tv;
}
Instead of
try this:
This is because list view reuses list item objects (
View convertView), so on scrolling you get an already usedtvand its views are already populated with some values.