2017-01-09 3 views
2

(R.drawable.logo)objectstringに変換して、listviewに表示したいとします。私はそれのために次のコードを使用しますが、それはあなたがあなたのイメージは、Base64文字列に変換する必要はありませんSimpleAdapterを使用してListViewで画像を表示するにはAndroidでImage ListViewを取得するにはどうすればよいですか?

Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.logo); 
ByteArrayOutputStream ByteStream = new ByteArrayOutputStream(); 
bitmapOrg.compress(Bitmap.CompressFormat.PNG,100, ByteStream); 
byte [] b = ByteStream.toByteArray(); 
String temp = Base64.encodeToString(b, Base64.DEFAULT); 

ListAdapter adapter = new SimpleAdapter(
    Welcome.this, 
    contactList, 
    R.layout.about, 
    new String[] { TAG_NAME, TAG_SURNAME, temp }, 
    new int[] { R.id.name, R.id.surname, R.id.imageView} 
); 

list.setAdapter(adapter); 

ERROR: Unable to decode stream: java.io.FileNotFoundException: : open failed: ENOENT (No such file or directory)

+0

あなたは画像の文字列値を取得していますか? –

+1

ビットマップをBase64文字列に変換したいのですか? –

+0

@BoldijarPaulはい私はそれを試しても動作していない – gaddarHamolka

答えて

0

を動作しませんでした。

new String[] { TAG_NAME, TAG_SURNAME, temp }からnew String[] { TAG_NAME, TAG_SURNAME, TAG_IMAGE }に変更してください。あなたのcontactList、アレイ内

次のように画像を追加し、

for(int i = 0; i < length; i++){ 
    HashMap<String, String> hm = new HashMap<String,String>(); 
    hm.put(TAG_NAME, names[i]); 
    hm.put(TAG_SURNAME, surnames[i]); 
    hm.put(TAG_IMAGE, Integer.toString(R.drawable.logo)); 
    contactList.add(hm); 
} 

これは、すべての行に対してR.drawable.logoを設定します。

ただし、取得しているエラーはFileNotFoundExceptionです。画像も存在するかどうかを確認してください。

チェックthis SOスレッド。

+1

タンクあまりにも@K Neerajラル – gaddarHamolka

関連する問題