0

我正在使用从 JSON 数组中获取的数据填充列表视图。当我在列表视图上滚动时,我得到的元数据正在被复制。

        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;
      }
4

1 回答 1

2

代替

t.setText (t.getText() + "\n"+ "When:" + "\t"+meta.getString( ...

试试这个:

t.setText("When:" + "\t"+meta.getString( ...)

这是因为列表视图重用View convertViewtv列表项对象(

于 2012-06-27T21:58:48.783 回答