Bonjour,
J'ai suivi ce tuto de developpez pour créer une listeView.
Mais je rencontre un probleme lors de l'appel adapter.addListenner(this);
-Erreur au passage de la souris sur le this
-Erreur du compilateur[..] cannot be applied to [...]
Voici mes fichiers:Error22, 29) error: incompatible types: AnnonceAnimalPerduActivity cannot be converted to AnnonceAnimalPerduAdapterListener
AnnonceAnimalPerduActivity.java
AnnonceAnimalPerduAdapter.java
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
27
28
29
30
31
32
33
34
35
36
37
38 package studio.com.warnan.AnnoncePerdu; import android.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ListView; import java.util.ArrayList; import studio.com.warnan.R; public class AnnonceAnimalPerduActivity extends AppCompatActivity implements AnnonceAnimalPerduAdapterListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_annonce_perdu); ArrayList<AnnonceAnimalPerdu> listAnnonceAnimalPerdu = AnnonceAnimalPerdu.getAListOfAnimalPerdu(); AnnonceAnimalPerduAdapter adapter = new AnnonceAnimalPerduAdapter(this, listAnnonceAnimalPerdu); adapter.addListener(this); ListView list = (ListView)findViewById(R.id.ListView01); list.setAdapter(adapter); } @Override public void onClickButtonImage(AnnonceAnimalPerdu item, int position) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Annonce Animal"); builder.setMessage("Vous avez clique sur : " + item.id_Annonce_AnimalPerdu); builder.setPositiveButton("Oui", null); builder.setNegativeButton("Non", null); builder.show(); } }
AnnonceAnimalPerdu.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 package studio.com.warnan.AnnoncePerdu; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; import studio.com.warnan.R; public class AnnonceAnimalPerduAdapter extends BaseAdapter { private List<AnnonceAnimalPerdu> mListAnnonceAnimalPerdu; private Context mContext; private LayoutInflater mInflater; public AnnonceAnimalPerduAdapter(Context context, List<AnnonceAnimalPerdu> aListAnnonceAnimalPerdu) { mContext = context; mListAnnonceAnimalPerdu = aListAnnonceAnimalPerdu; mInflater = LayoutInflater.from(mContext); } public int getCount() { return mListAnnonceAnimalPerdu.size(); } public Object getItem(int position) { return mListAnnonceAnimalPerdu.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { LinearLayout layoutItem; if (convertView == null) { layoutItem = (LinearLayout) mInflater.inflate(R.layout.annonceanimalperdu_layout, parent, false); } else { layoutItem = (LinearLayout) convertView; } TextView id_annonce = (TextView)layoutItem.findViewById(R.id.textView_id_annonce_perdu); //TextView date_perte = (TextView)layoutItem.findViewById(R.id.textView_date_perte); Button button_image = (Button)layoutItem.findViewById(R.id.button_photo_animal); TextView type_animal = (TextView)layoutItem.findViewById(R.id.textView_type_animal); TextView lieu_perte = (TextView)layoutItem.findViewById(R.id.textView_lieu_perdu); //Drawable drawable = (Drawable)layoutItem.findViewById(R.drawable.uski); id_annonce.setText(mListAnnonceAnimalPerdu.get(position).id_Annonce_AnimalPerdu); //date_perte.setText(mListAnnonceAnimalPerdu.get(position).date_Annonce_AnimalPerdu); //button_image.setBackground(mListAnnonceAnimalPerdu.get(position).urlImage_AnimalPerdu); type_animal.setText(mListAnnonceAnimalPerdu.get(position).type_AnimalPerdu); lieu_perte.setText(mListAnnonceAnimalPerdu.get(position).lieu_AnimalPerdu); button_image.setTag(position); button_image.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Integer position = (Integer)v.getTag(); sendListener(mListAnnonceAnimalPerdu.get(position), position); } }); return layoutItem; } private ArrayList<AnnonceAnimalPerduAdapterListener> mListListener = new ArrayList<AnnonceAnimalPerduAdapterListener>(); public void addListener(AnnonceAnimalPerduAdapterListener aListener) { mListListener.add(aListener); } private void sendListener(AnnonceAnimalPerdu item, int position) { for(int i = mListListener.size()-1; i >= 0; i--) { mListListener.get(i).onClickButtonImage(item, position); } } /** * Interface pour �couter les �v�nements sur le nom d'une personne */ public interface AnnonceAnimalPerduAdapterListener { public void onClickButtonImage(AnnonceAnimalPerdu item, int position); } }
AnnonceAnimalPerduAdapterListener.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 package studio.com.warnan.AnnoncePerdu; import java.util.ArrayList; import java.util.Date; public class AnnonceAnimalPerdu { public int id_Annonce_AnimalPerdu=0; public Date date_Annonce_AnimalPerdu=new Date(); public String type_AnimalPerdu; public String lieu_AnimalPerdu; public String urlImage_AnimalPerdu; public AnnonceAnimalPerdu(int id_Annonce_AnimalPerdu, Date date_Annonce_AnimalPerdu, String type_AnimalPerdu, String lieu_AnimalPerdu, String urlImage_AnimalPerdu) { id_Annonce_AnimalPerdu = this.id_Annonce_AnimalPerdu; date_Annonce_AnimalPerdu = this.date_Annonce_AnimalPerdu; type_AnimalPerdu = this.type_AnimalPerdu; lieu_AnimalPerdu = this.lieu_AnimalPerdu; urlImage_AnimalPerdu = this.urlImage_AnimalPerdu; } /** * Initialise une liste de personnes * @return une liste de "AnnonceAnimalPerdu" * Les valeurs des attributs permettant l'initialisation des objets annonces d'animaux perdu devront être requêté en base de donnée */ public static ArrayList<AnnonceAnimalPerdu> getAListOfAnimalPerdu() { ArrayList<AnnonceAnimalPerdu> listAnnonceAnimalPerdu = new ArrayList<AnnonceAnimalPerdu>(); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(0, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(1, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(2, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(3, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(4, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(5, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(6, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(7, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(8, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(9, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(10, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(11, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(12, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(13, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); listAnnonceAnimalPerdu.add(new AnnonceAnimalPerdu(14, new Date(), "Type Animal", "Lieu Perte", "URL de l'image")); return listAnnonceAnimalPerdu; } }
annonceanimalperdu_layout.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 package studio.com.warnan.AnnoncePerdu; /** * Interface pour écouter les évènements sur l'image d'un item AnnonceAnimalPerdu */ public interface AnnonceAnimalPerduAdapterListener { public void onClickButtonImage(AnnonceAnimalPerdu item, int position); }
activity_annonce_perdu.xml
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/LL_Fond"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView_label_annonce_perdu" android:background="@drawable/rectangle"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rectangle" android:gravity="center_vertical|center_horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="ID Annonce" android:id="@+id/textView_id_annonce_perdu" android:gravity="center_horizontal" android:layout_marginRight="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text=" | " android:id="@+id/textView_separator" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Date de perte" android:id="@+id/textView_date_perte" android:layout_marginLeft="10dp" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical"> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/button_photo_animal" android:background="@drawable/uski" android:layout_margin="8dp" android:gravity="center_vertical" /> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical|center_horizontal" android:layout_marginLeft="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Type Animal" android:id="@+id/textView_type_animal" /> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical|center_horizontal" android:layout_marginLeft="5dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text=" perdu à " android:id="@+id/textView_perdu" /> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical|center_horizontal" android:layout_marginLeft="5dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Lieu" android:id="@+id/textView_lieu_perdu" /> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout>
J'ai essayé plusieurs choses mais sans succès.
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="studio.com.warnan.AnnoncePerdu.AnnonceAnimalPerduActivity"> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/frameLayout" android:layout_marginBottom="10dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Annonces d'animals perdus :" android:id="@+id/textView_label_annonce_perdu" android:gravity="center_horizontal" /> </FrameLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/frameLayout"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView_label_annonce_perdu" android:background="@drawable/rectangle"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rectangle" android:gravity="center_vertical|center_horizontal"> <ListView android:id="@+id/ListView01" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ListView> </LinearLayout> </LinearLayout> </LinearLayout> </RelativeLayout>
Si vous pouviez me donner un pti coup de pouce, ce serait sympa
Partager