0

我有一个列表视图,其中包含来自 twitter 的数据。我想显示推特,但它在每个推特项目中都显示了用户。所以我想为其他用户显示默认图片。我的代码正在运行,但是当我移动 listview 时,每个用户的用户个人资料图像都会再次出现。我该如何解决?如果它是转推,则在代码“rt”中。

protected void onPostExecute(String result) {
            super.onPostExecute(result);

            if (null != pDialog && pDialog.isShowing()) {
                pDialog.dismiss();
            }

            if (null == result || result.length() == 0) {
                showToast("Bağlantı yok");
                Twitter.this.finish();
            } else {

                List<String> galleryImages = new ArrayList<String>();
                try {         JSONObject jsonObject = new JSONObject(result);  
                 veriArray = jsonObject.getJSONArray("results");    
                int nVeri = veriArray.length();      
                for (int i = 0; i < nVeri; i++) {   
                    JSONObject veriObject = veriArray.getJSONObject(i);   


                    baslik = veriObject.getString("text");        
                    kImaj = veriObject.getString("profile_image_url");      
                    kisaAciklama = veriObject.getString("from_user_name"); 

                    Item objItem = new Item();

                    rt=baslik.substring(0, 2);

                    if(rt.equals(kiyas)){



                        kImaj="";
                        objItem.setLink(kImaj);
                        objItem.setName(baslik);}   

                    else {
                        objItem.setLink(kImaj);
                        objItem.setName(baslik);
                    }


                    arrayOfList.add(objItem);




                    //objItem.setLink(link);





                        }  

                } catch (JSONException e)
                {         e.printStackTrace();     } } 



                Collections.sort(arrayOfList, new Comparator<Item>() {

                    public int compare(Item lhs, Item rhs) {
                        return (lhs.getAge() - rhs.getAge());
                    }
                });
                setAdapterToListview();

            }

        }

我的适配器

public class KampanyaRowAdapter extends ArrayAdapter<Item> {

    private Activity activity;
    private List<Item> items;
    private Item objBean;
    private int twitterrow;
    private ImageLoader imageLoader;
    public KampanyaRowAdapter(Activity act, int resource, List<Item> arrayList) {
        super(act, resource, arrayList);
        this.activity = act;
        this.twitterrow = resource;
        this.items = arrayList;
        imageLoader = new ImageLoader(act);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder holder;
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(twitterrow, null);

            holder = new ViewHolder();
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        if ((items == null) || ((position + 1) > items.size()))
            return view;

        objBean = items.get(position);

        holder.tvName = (TextView) view.findViewById(R.id.tvname);
        holder.tvCity = (TextView) view.findViewById(R.id.tvcity);


        holder.imgView = (ImageView) view.findViewById(R.id.image);

        if (holder.tvName != null && null != objBean.getName()
                && objBean.getName().trim().length() > 0) {
            holder.tvName.setText(Html.fromHtml(objBean.getName()));
        }
        if (holder.tvCity != null && null != objBean.getCity()
                && objBean.getCity().trim().length() > 0) {
            holder.tvCity.setText(Html.fromHtml(objBean.getCity()));
        }

        if (holder.imgView != null) {
            if (null != objBean.getLink()
                    && objBean.getLink().trim().length() > 0) {
                imageLoader.DisplayImage(objBean.getLink(), activity,
                        holder.imgView);
            } else {

            }
        }

        return view;
    }

    public class ViewHolder {
        public TextView tvName, tvCity, tvBDate, tvGender, tvAge;
        private ImageView imgView;
    }
}
4

1 回答 1

0

如果您共享适配器代码会有所帮助,这可能是您的适配器正在回收旧视图。检查适配器中的newViewbindView方法。

于 2012-11-06T12:46:13.357 回答