Ich brauche Ihre Hilfe, um ein Bild innerhalb eines Objekts in Array hinzuzufügen. Ich habe meine MainActivity
, die ArrayList
Item Objekte erstellen. Die Item-Klasse wird für jeden Objektnamen und jede ID angegeben. Jetzt brauche ich deine Hilfe, um irgendeine Funktion anzuwenden, die zu diesem Bild hinzufügt, die mit dem Layout verbinden.Android - initialisieren Bild von beim Erstellen neuer Artikel
MainActivity, die neue Objekte erstellen -
ArrayList<Item> arrayList = new ArrayList<>();
arrayList.add(new Item("a", 0));
arrayList.add(new Item("b", 1));
arrayList.add(new Item("c", 2));
arrayList.add(new Item("d", 3));
Item-Klasse (In dieser Klasse muss ich das Bild auf das Objekt initialisieren) -
public class Item {
private final String name;
private final int id;
public Item(String name, int id) {
this.name = name;
this.id = id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
Mein Layout -
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:elevation="5dp"
android:layout_margin="@dimen/item_margin"
android:layout_width="wrap_content"
android:layout_height="@dimen/item_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/text_item"
android:gravity="center"
android:layout_gravity="center" />
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher" />
</android.support.v7.widget.CardView>
Danke für jede Hilfe!
tun Sie das Bild von Ressourcenordner oder von einer URL angezeigt werden soll? –
@Sandeepdhiman von einer URL – ironto99