2012-11-06 40 views
0

我有一個來自twitter的數據的列表視圖。我想展示twits,但它顯示了每個twit項目中的用戶。所以我想爲其他用戶顯示默認圖片。我的代碼正在工作,但是當我移動listview時,用戶配置文件圖像再次爲每個用戶提供。如果它是轉推,我可以如何解決?代碼「rt」。android listview移動變化

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; 
    } 
} 
+1

在服務器的listview中使用延遲加載圖像。 http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview去爲此 –

+0

有無論如何鎖定列表視圖後,我解析。? – slhgndz

回答

0

,如果你共享你的適配器代碼這將有所幫助,也可能是您的適配器回收舊的觀點。檢查適配器中的newViewbindView方法。

+0

我的一些列表項從js​​on解析圖像,但我想要一些有默認背景。當活動開始時沒問題,但是當我在列表視圖中查看時,所有圖像查看都顯示來自json的圖像。 – slhgndz