Bonjour,
Je n'arrive pas à inclure dans ma liste la gestion du clic sur le bouton de chaque item. Normalment lors du clic sur le bouton il y aura lancement d'une nouvelle activité en lui envoyant les paramètres de l'item sélectionné (id, tel, nom, etc)
J'ai essayé de testé juste avec un toast dans la méthode onClick() mais ça ne fonctionne pas. ou devrai-je mettre alors la fonction onClick()?
voilà ma classe:
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
public class GetChoiceActivity extends ListActivity implements OnClickListener {
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.resultat_list);
 
        Intent i = getIntent();
	     city = i.getStringExtra(ResearchActivity.CITY);
	     field = i.getStringExtra(ResearchActivity.FIELD);
	     country = i.getStringExtra(ResearchActivity.COUNTRY);
	   //  Toast.makeText(GetChoiceActivity.this, "city is: " + city + " field is: " + field, Toast.LENGTH_LONG).show();
        // Hashmap for ListView
        centersList = new ArrayList<HashMap<String, String>>();
 
        registerForContextMenu(getListView());
        // Loading products in Background Thread
        new LoadAllCenters().execute();
 
    }
class LoadAllCenters extends AsyncTask<String, String, String> {
 
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(GetChoiceActivity.this);
            pDialog.setMessage("Loading list of training centers. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }
 
        /**
         * getting All products from url
         * */
        protected String doInBackground(String... args) {
            // Building Parameters
        	 Log.d("detail choice ","country is: " + country + "city is: " + city + " field is: " + field);
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("country", country));
            params.add(new BasicNameValuePair("city", city));
            params.add(new BasicNameValuePair("field", field));
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
 
            // Check your log cat for JSON reponse
           Log.d("Centers with selected options are: ", json.toString());
 
            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);
 
                if (success == 1) {
                    // products found
                    // Getting Array of Products
                    centers = json.getJSONArray(TAG_PRODUCTS);
 
                    // looping through All Products
                    for (int i = 0; i < centers.length(); i++) {
                        JSONObject c = centers.getJSONObject(i);
 
                        // Storing each json item in variable
                        String id = c.getString(TAG_PID);
                        String name = c.getString(TAG_NAME);
                        String tel = c.getString(TAG_TEL);
                        String address = c.getString(TAG_ADDRESS);
                        String field = c.getString(TAG_FIELD);
                        String city = c.getString(TAG_CITY);
                        String country = c.getString(TAG_COUNTRY);
                        String email = c.getString(TAG_EMAIL);
                        double longitud = c.getDouble(TAG_LONG);
                        String longitude = Double.toString(longitud);
                        double lati = c.getDouble(TAG_LAT);
                        String latitude = Double.toString(lati);
                        String link = c.getString(TAG_LINK);
 
                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();
 
                        // adding each child node to HashMap key => value
                        map.put(TAG_PID, id);
                        map.put(TAG_NAME, name);
                        map.put(TAG_TEL, tel);
                        map.put(TAG_ADDRESS, address);
                        map.put(TAG_CITY, city);
                        map.put(TAG_COUNTRY, country);
                        map.put(TAG_FIELD, field);
                        map.put(TAG_EMAIL, email);
                        map.put(TAG_LONG, longitude);
                        map.put(TAG_LAT, latitude);
                        map.put(TAG_LINK, link);
 
 
                        // adding HashList to ArrayList
                        centersList.add(map);
                        list = new ArrayList<String>(map.values());
                    }
                } 
            } catch (JSONException e) {
                e.printStackTrace();
            }
 
            return null;
        }
 
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all products
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                    ListAdapter adapter = new SimpleAdapter(
                    		GetChoiceActivity.this, centersList,
                            R.layout.trackrow, new String[] {
                                    TAG_NAME},
                            new int[] { R.id.textName });
                    // updating listview
                    setListAdapter(adapter);
 
                }
            });
 
        }
 
    }
   	@Override // Selection d'un item de la liste
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Map<String,String> item =  (Map<String, String>) l.getItemAtPosition(position);
 
		 _id = item.get(TAG_PID);
		name = item.get(TAG_NAME);
		 tel = item.get(TAG_TEL);
		 email = item.get(TAG_EMAIL);
		address = item.get(TAG_ADDRESS);
		String longitud = item.get(TAG_LONG);
		 longitude = Double.parseDouble(longitud);
		String latitud = item.get(TAG_LAT);
		 latitude = Double.parseDouble(latitud);
		 link = item.get(TAG_LINK);
		 Intent details = new Intent(GetChoiceActivity.this, OptionsMenu.class);
			details.putExtra(ID, _id);
			details.putExtra(ADDRESS, address);
			details.putExtra(EMAIL, email);
			details.putExtra(LINK, link);
			details.putExtra(LONG, longitude);
			details.putExtra(LAT, latitude);
			details.putExtra(NAME, name);
			details.putExtra(TEL, tel);
			details.putExtra(LINK, link);
			startActivity(details);	
 
 
		//Intent details = new Intent(GetChoiceActivity.this, DetailActivity.class);
		//details.putExtra(ID, _id);
		//startActivity(details);	
		//Toast.makeText(GetChoiceActivity.this, "l'identifiant est: " + _id , Toast.LENGTH_LONG).show();
 
		//v.showContextMenu();
 
	}
@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		Toast.makeText(GetChoiceActivity.this, "test clic "  , Toast.LENGTH_LONG).show();
 
	}
}
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
<?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:orientation="vertical" 
    android:background="@drawable/lancement2">
 
 
     <ListView
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:id="@android:id/list"
    />
 
</LinearLayout>
Liste:
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
<?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" android:id="@+id/background"
	>
 
	<RelativeLayout android:layout_centerVertical="true"
		android:paddingLeft="4dp" android:layout_width="wrap_content"
		android:layout_height="wrap_content">
 
		<TextView android:id="@+id/textName"
			android:layout_width="wrap_content" android:layout_height="wrap_content"
			android:textStyle="bold" 
			android:shadowColor="@color/black" android:shadowRadius="0.5"
			android:shadowDx="0" android:shadowDy="0"  android:layout_marginLeft="4dip"></TextView>
 
	</RelativeLayout>
 
	<Button android:id="@+id/track_button"
		android:text="Details" android:layout_alignParentRight="true" android:layout_centerVertical="true"
		android:layout_width="wrap_content" android:layout_height="fill_parent"></Button>
 
 
 
</RelativeLayout>
Pouvez vous m'aider?
Merci