2013-04-28 3 views
1

전자 상거래 응용 프로그램에서 작업 중입니다. 제품 - 이미지 = 하나의 ImageView 및 일부 textViews - 데이터베이스에서 제품 목록을 표시해야하지만 추출 할 때 데이타베이스의 데이타는, imageView를 제외하고는 everting이 잘 작동하고, 소스 배치에있는 것과 같은 이미지를 보여줍니다.내 목록보기에서 이미지 소스를 변경할 수 없습니다.

이것은 내 어댑터의 getView() 메소드입니다. 당신은 배경을 변경

<?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> 

답변

0

하지 전경 아래

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

소스 레이아웃입니다. ImageView에는 foregrond 및 background 이미지가 모두 있습니다. 대신

holder.imageDuProduit.setBackgroundDrawable(drawableImage); 

사용

holder.imageDuProduit.setImageDrawable(drawableImage); 
+0

그래 즉, 지금은 모든 것이 잘 작동 감사되고있다. –

관련 문제