Bonjour ! Encore une fois je me tourne vers vous pour certainements une choses simples pour certains ici. J'apprend un peu plus chaque jour.
Aujour'hui je dois gérer une listview, plus precisement, ajouter une imageview dans la liste view pour chaque item ! Chose faites ! MAintenant la où sa coince, c'est qu'en plus de sa j'aimerai modifier l'image d'arrire plan (background) de chaque item avex une image détenu dans /Drawable. Je précise pour exemple, imaginons 5 items, il y aura donc 5 background different! Donc je suis parti sur la piste d'un tableau de Drawable sans sucees etc... JE vous met le code si dessous, sa sera plus clair pour les vrais: Premierement, l'affichage xml d'un item :
Deuxièmement : Ma listview :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="600dp" android:paddingLeft="55dp" android:scaleType="centerInside" /> </LinearLayout>
Et troisiemement le code JAVA associé :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.clashesque.antholife.labibleclashesque.ListesCoc" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/lcoc" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 String[] values = new String[] { String.valueOf(R.drawable.canon)/*Canon*/,String.valueOf(R.drawable.tesla)/*TeslaCamouflée*/,String.valueOf(R.drawable.tds)/*TourDeSorcier*/}; ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>(); for(int x=0; x<=2; x++){ HashMap<String, String> map = new HashMap<String, String>(); map.put("img", values[x]); listItem.add(map); } SimpleAdapter init = new SimpleAdapter(this.getBaseContext(), listItem, R.layout.affichage, new String[] {"img"}, new int[] {R.id.img}); mCoc.setAdapter(init); mCoc.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { Intent intent = new Intent(ListesCoc.this, Canon.class); startActivity(intent); }
Donc concretement j'aimerai modifier pour chaque item , l'arriere plan ppur chaque item je precise et etant different ! Un peu comme ici où j'utilise hashmap pour envoyé les images correspondante dans chaque imageview pour chaque item.
MERCI !!!!!
Partager