2016-12-22 5 views
-1

RecyclerViewに画像を表示しています。画像のソースはMMSメッセージから取得したビットマップです。問題は、画像が表示されていないことです。絶対に何も表示されません。ここに私のonBindViewです:ImageView.setImageBitmapがRecyclerViewに画像を表示しない

@Override 
public void onBindViewHolder(ViewHolder holder, int position) { 
    // - get element from your dataset at this position 
    // - replace the contents of the view with that element 
    final String name = mDataset.get(position).getContact() ; 
    final MMSMessage message = mDataset.get(position); 
    holder.txtHeader.setText(name); 
    DateTime dateTime = new DateTime(message.getDate()); 
    holder.txtDate.setText(dateTime.toString(Globals.generalSQLFormatterDT)); 
    holder.txtText.setText(message.getBody()); 
    holder.txtText.setVisibility(View.VISIBLE); 
    Bitmap bitmap = message.getBitmap(); 
    if (bitmap != null) { 
     //bitmap is not null and I can see an image using Android Studio 
     bitmap =Bitmap.createScaledBitmap(bitmap, 120, 120, false); 
     holder.imgMMS.setImageBitmap(bitmap); 

    } else { 
     holder.imgMMS.setVisibility(View.GONE); 
    } 

} 

ImageViewのためのXML:

<ImageView 
    android:layout_below="@+id/thirdLine" 
    android:id="@+id/imageMMS" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginRight="6dip" 
    android:contentDescription="TODO" 
    /> 

私はhereを見て、任意の小さなサイズに画像を縮小しようとしました。私はそれがメモリ不足ではないとは思わない - 私はテストとしてランチャーのアイコンを入れてみました。私は間違って何をしていますか?

+0

なぜ 'if'では' else'にアクションopossiteはありませんか? – Selvin

+0

@Selvinあなたは何を意味するのか分かりませんか? –

+0

「else」には1つの「action」しかありません... ifのopossiteアクションはどこですか...私はすべての同様の質問に対してペニーを取得したいと思います... – Selvin

答えて

1
if (bitmap != null) { 
     //bitmap is not null and I can see an image using Android Studio 
     bitmap =Bitmap.createScaledBitmap(bitmap, 120, 120, false); 
     holder.imgMMS.setImageBitmap(bitmap); 
holder.imgMMS.setVisibility(View.GONE); 
    } else { 
     holder.imgMMS.setVisibility(View.GONE); 
    } 

可視性をGONEに設定しています。私の推測では、RecyclerViewはビューをリサイクルしていて、Visibleに設定していないので、ビューはGONEになります。 holder.imgMMS.setVisibility(View.VISIBLE)を追加してみてください。ビットマップがnullでない場合は、次のようになります。

if (bitmap != null) { 
     //bitmap is not null and I can see an image using Android Studio 
     bitmap =Bitmap.createScaledBitmap(bitmap, 120, 120, false); 
     holder.imgMMS.setImageBitmap(bitmap); 
     holder.imgMMS.setVisibility(View.VISIBLE); 
    } else { 
     holder.imgMMS.setVisibility(View.GONE); 
    } 
+0

それはそれでした。くだらない! –

関連する問題