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();
}
感謝您的回覆,我已經聽說過懶加載,但我可以用它在定製佈局而不是使用ListView? 我想知道我的代碼中存在什麼問題,你能告訴我嗎? :) –
明確告訴我什麼是你的prblm? – Mohan
問題是在imageview中顯示圖像時,正如你知道當我們使用充氣機時,佈局的ID是固定的,當我將位圖設置到圖像視圖並使用充氣器顯示視圖時,所有圖像視圖中的一個被顯示並且其他人沒有改變。 我試圖在添加視圖之前將其設置爲圖像視圖,結果是除了一個之外都顯示了所有圖像,並且它導致了圖像中顯示的位圖結果發生偏移,我清楚了嗎? –