Je veux créer un listview qui immédiatement après initialisé dans la méthode onCreate() ajoutera des images SEULEMENT à certains champs, et je n'ai aucune idée de comment faire cela.Android - affichage des images listview dans onCreate()
Voici la partie nécessaire de ma méthode onCreate():
((ListView) findViewById(android.R.id.list)).setClickable(true);
for(int i=0; i<num_enter; i++){
adapter=new SimpleAdapter(this, listItems, R.layout.custom_row_view,new String[]{"name", "current", "image"}, new int[] {R.id.text1, R.id.text2, R.id.lockImage});
setListAdapter(adapter);
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("name", name[i]);
SetSql getport = new SetSql(this);
getport.open();
int port = getport.getSingleProtect(i);
getport.close();
if(port==1){
//THIS IS WHERE I WANT TO SET THE IMAGE
temp.put("current", Integer.toString(current[i]));
}else{
temp.put("current", Integer.toString(current[i]));
}
listItems.add(temp);
adapter.notifyDataSetChanged();
}
}else{
((ListView) findViewById(android.R.id.list)).setClickable(false);
adapter=new SimpleAdapter(this, listItems, R.layout.custom_row_view,new String[]{"name", "current"}, new int[] {R.id.text1, R.id.text2});
setListAdapter(adapter);
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("name", "You have no enteries yet!");
temp.put("current", "");
listItems.add(temp);
adapter.notifyDataSetChanged();
}
Voici mon custome_row_view.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"
>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/lockImage"
/>
<TextView android:id="@+id/text1"
android:textSize="25dp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView android:id="@+id/text2"
android:textSize="25dp"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"/>
</RelativeLayout>
Merci pour toute aide !!!
Je ne suis pas vraiment familier avec les listes, et je suis presque sûr que je peux modifier mon propre code pour ajouter des images à certains éléments Listview. Je ne sais pas comment. – arielschon12