2013-10-04 68 views
0

我正在开发一个应用程序,用于通过PHP使用JSON检索数据,我需要检索文本和图像,数据库中的每一行都包含一个URL我需要在我的应用程序中显示的图像。 问题是,当我想膨胀一个新的视图,我设置了一个文本和一个ImageView,文本工作很好,但在ImageView中的问题,该图像只显示一个ImageView,我试图为该图像设置ID充气后查看,因此部分问题已解决,所有图像浏览都会显示,除了其中一个,并且图像显示在错误的图像视图中。 所以我想知道是什么问题? 在这段代码中,我试图设置两个textview和一个位图到imageview,textviews很好,但在imageview中的问题,正如我上面解释的。 我将位图转换为Backgroud中的字符串,在这里我再次将字符串转换为位图。 这里是OnPostExecute()方法。如何为多个图像视图设置位图

protected void onPostExecute(ArrayList<String> arrayList) { 
     LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     LinearLayout Offers =(LinearLayout)findViewById(R.id.off); 
     for(int i=0;i<arrayList.size();i++) 
     { 
     View view = inflater.inflate(R.layout.offers, null); 
     o1 = (RelativeLayout) view.findViewById(R.id.o1); 
     off_det = (TextView) view.findViewById(R.id.offer_details); 
     off_pri = (TextView) view.findViewById(R.id.offer_price); 
     offer_pic = (LinearLayout) findViewById(R.id.offerpic); 
     off_det.setText(arrayList.get(i)); 
     final String x = (arrayList.get(i)); 
     if(i<arrayList.size()-1){i++; 
     off_pri.setText(arrayList.get(i)); 
     i++; 
     try{ 
      byte [] encodeByte = Base64.decode(arrayList.get(i),Base64.DEFAULT); 
      Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); 
      BitmapDrawable background = new BitmapDrawable(bitmap); 
      offer_pic.setBackgroundDrawable(background); 
      offer_pic.setId(i); 
      }catch(Exception e){ 
      e.getMessage(); 
      } 
     } 
     Offers.addView(view); 
     o1.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       Intent intent = new Intent(OffersBox.this, ShopOffers.class); 
       intent.putExtra("x", x); 
       startActivityForResult(intent, 0); 
      } 
     }); 
     } 
    PD.dismiss(); 
     } 

回答

0

嗨,你必须使用延迟加载更好的用户体验,因此请参考以下链接android lazy loading

+0

感谢您的回复,我已经听说过懒加载,但我可以用它在定制布局而不是使用ListView? 我想知道我的代码中存在什么问题,你能告诉我吗? :) –

+0

明确告诉我什么是你的prblm? – Mohan

+0

问题是在imageview中显示图像时,正如你知道当我们使用充气机时,布局的ID是固定的,当我将位图设置到图像视图并使用充气器显示视图时,所有图像视图中的一个被显示并且其他人没有改变。 我试图在添加视图之前将其设置为图像视图,结果是除了一个之外都显示了所有图像,并且它导致了图像中显示的位图结果发生偏移,我清楚了吗? –

相关问题