1

私は e コマース アプリケーションに取り組んでいます。データベースから製品のリストを表示する必要があります。ソース レイアウトと同じ画像が表示されます。

これは私のアダプターの getView() メソッドです。

public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;
    if (convertView==null)
    {
        holder=new ViewHolder();
        convertView = inflater.inflate(R.layout.lesproduits, null);
        holder.nomduProduit = (TextView)convertView.findViewById(R.id.nomProduit);
        holder.prixDuProduit = (TextView)convertView.findViewById(R.id.prixProduit);
        holder.imageDuProduit = (ImageView)convertView.findViewById(R.id.imageProduit);
        convertView.setTag(holder);
    }

    else
    {
        holder = (ViewHolder) convertView.getTag();
    }

    Bitmap bitmapImage = BitmapFactory.decodeFile(path+File.separator+lesProduits.get(position).getImage());
    Drawable drawableImage = new BitmapDrawable(bitmapImage);
    System.out.println(path+File.separator+lesProduits.get(position).getImage());

    holder.imageDuProduit.setBackgroundDrawable(drawableImage);
    holder.nomduProduit.setText(lesProduits.get(position).getNomDuProduit());
    holder.prixDuProduit.setText(lesProduits.get(position).getPrixDuProduit());
    return convertView;
}

以下はソースレイアウトです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/imageProduit"
    android:layout_width="100dp"
    android:layout_height="50dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="30dp"
    android:layout_marginTop="5dp"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/nomProduit"
    android:layout_marginTop="5dp"
    android:layout_width="170dp"
    android:layout_height="30dp"
    android:layout_toRightOf="@+id/imageProduit"
    android:text="Smart phone"
    android:textSize="25sp" />

<TextView
    android:id="@+id/prixProduit"
    android:layout_width="100dp"
    android:layout_height="30dp"
    android:layout_alignLeft="@+id/nomProduit"
    android:layout_below="@+id/nomProduit"
    android:layout_marginTop="5dp"
    android:text="Large Text"
    android:textSize="15sp" />

 </RelativeLayout>
4

1 に答える 1

0

前景ではなく、背景を変更しています。ImageView には、フォアグラウンド イメージとバックグラウンド イメージの両方があります。

これの代わりに

  holder.imageDuProduit.setBackgroundDrawable(drawableImage);

これを使って

 holder.imageDuProduit.setImageDrawable(drawableImage);
于 2013-04-28T14:08:06.960 に答える