私は次のコードを持っています:
list_home = (ListView) findViewById (R.id.list_home);
cursor2 = baza5.query("igralci", new String[] {"slika","ime", "priimek", "pozicija","visina","_id"},
"id_ekipe like " + id_izbrane_ekipe_domaci+" AND " +
"je_izbran like " + pomozni,
null, null, null, null);
adapter2 = new SimpleCursorAdapter(
this,
R.layout.igralci_ekipe,
cursor2,
new String[] {"slika","ime","priimek","pozicija","visina","_id"},
new int[] {R.id.slika_igralca,R.id.ime_igralca,R.id.priimek_igralca,R.id.pozicija_igralca,
R.id.visina_igralca,R.id.id});
list_home.setAdapter(adapter2);
そして私のigralci_ekipe.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8px">
<ImageView
android:id="@+id/slika_igralca"
android:layout_gravity="left"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="@+id/ime_igralca"
android:layout_width="wrap_content"
android:textColor="#0000ff"
android:textSize="15dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/slika_igralca" />
<TextView
android:id="@+id/priimek_igralca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#0000ff"
android:textSize="15dp"
android:layout_marginLeft="16px"
android:layout_toRightOf="@id/ime_igralca" />
<TextView
android:id="@+id/pozicija_igralca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#0000ff"
android:textSize="15dp"
android:layout_marginLeft="16px"
android:layout_toRightOf="@id/priimek_igralca"/>
<TextView
android:id="@+id/visina_igralca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#0000ff"
android:textSize="15dp"
android:layout_marginLeft="16px"
android:layout_toRightOf="@id/pozicija_igralca"/>
<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:textColor="#0000ff"
android:textSize="1dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16px"
android:layout_toRightOf="@id/visina_igralca"/>
</RelativeLayout>
データベースフィールドslika(picture)は、SDカード上の私の画像の文字列パスです。
これは動作し、画像は正しく表示されますが、ロードする画像が3つ以上ある場合、メモリエラーが発生します。
Is there a way I could use picture bitmap like this:
int targetW = slika_igralca.getWidth();
int targetH = slika_igralca.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath, bmOptions);
slika_igralca.setImageBitmap(bitmap);
次に、文字列として次のようなものを使用します。slika_igralca.setImageBitmap(bitmap);