Ich bin neu in Android-Entwicklung. Ich versuche, mein Layout für benutzerdefinierte Listenansichtselemente zu erstellen. Ich möchte wissen, wie ich Bildpfad geben werde, wenn ich ein ImageView im Mai-Layout habe.Benutzerdefinierte Listenansicht Artikel Layouts
Activity-Datei, wo ich diese Listview
ListView lstItems = (ListView) findViewById(R.id.lstItems);
String[] from = new String[]{"itemname", "productimage"};
int[] to = new int[]{R.id.itemname, R.id.productimage};
List<HashMap<String, Object>> fillMaps = new ArrayList<HashMap<String, Object>>();
for (Item item : objects) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("itemname", item.getName());
map.put("productimage", item.getImages());
fillMaps.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.shop_listitem_view, from, to);
lstItems.setAdapter(adapter);
Layout-Datei am bevölkern:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:id="@+id/itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="19dp"
android:layout_marginTop="22dp"
android:text="TextView"
android:textSize="14sp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/productimage" />
<ImageView
android:id="@+id/productimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="21dp"
app:srcCompat="@drawable/common_full_open_on_phone"
android:layout_alignTop="@+id/itemname"
android:layout_alignParentStart="true" />
</RelativeLayout>
also, was ist der Fehler? –
Wie fülle ich Bildpfad/URL für das ImageView? –
Sie befinden sich auf einem Server oder in Ihrem Projekt? –