IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Adapter XML au résultat de requête


Sujet :

Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Avril 2013
    Messages : 139
    Points : 24
    Points
    24
    Par défaut Adapter XML au résultat de requête
    Bonsoir,

    J'ai sur mon application, une requête qui permet de retourner tous les lieux dans la base de données, mais j'aimerais ajouter a chaque lieux retourner un bouton supprimer le lieux (donc il serait affecter au lieux précis)
    Comment adapter le nombre de bouton supprimer aux nombre de lieux retourner ?
    Mais j'en ai aucune idée de comment je pourrais faire...

    Merci de votre aide

    Ps : je debute

  2. #2
    Expert confirmé
    Avatar de Hephaistos007
    Profil pro
    Enseignant Chercheur
    Inscrit en
    Décembre 2004
    Messages
    2 493
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 493
    Points : 4 166
    Points
    4 166
    Par défaut
    Par exemple, tu peux utiliser une ListView pour afficher les lieux et considérer qu'un clic sur chaque item déclanche sa suppression coté serveur.
    Il vaut mieux mobiliser son intelligence sur des conneries que mobiliser sa connerie sur des choses intelligentes --- devise SHADOKS

    Kit de survie Android : mon guide pour apprendre à programmer sur Android, mon tutoriel sur les web services et enfin l'outil en ligne pour vous faire gagner du temps - N'oubliez pas de consulter la FAQ Android

  3. #3
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    139
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Avril 2013
    Messages : 139
    Points : 24
    Points
    24
    Par défaut
    Merci j'ai essayé mais en vain,

    A cause du extends Fragment cela pose un soucis....


    J'ai mis en police plus grande , les lignes qui posent porblemes avec fragment.



    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
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    package admin;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    
    import jordan.map.R;
    
    import org.apache.http.NameValuePair;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import JSON.JSONParser;
    import android.app.Fragment;
    import android.app.ProgressDialog;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.os.StrictMode;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.TextView;
    
    public class AdminCommentFragment extends Fragment {
    	// Progress Dialog
    	private ProgressDialog pDialog;
    
    	// Creating JSON Parser object
    	JSONParser jParser = new JSONParser();
    
    	ArrayList<HashMap<String, String>> commentsList;
    
    	// url to get all comments list
    	private static String url_all_comments = "http://10.0.2.2/get_all_comments.php";
    	private static String url_comments_reported = "http://10.0.2.2/get_comments_reported.php";
    
    	// JSON Node names
    	private static final String TAG_SUCCESS = "success";
    	private static final String TAG_COMMENTS = "comments";
    	private static final String TAG_ID = "id";
    	private static final String TAG_CONTENT = "content";
    	private static final String TAG_LOGIN = "login";
    	// comments JSONArray
    	JSONArray comment = null;
    
    	private Button comments = null, reportedComments = null;
    	private TextView managementOfComments = null;
    	private View rootView;
    
    	private ListView lv;
    
    	public AdminCommentFragment() {
    	}
    
    	@Override
    	public View onCreateView(LayoutInflater inflater, ViewGroup container,
    			Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    
    		rootView = inflater.inflate(R.layout.admin_comment, container, false);
    
    		comments = (Button) rootView.findViewById(R.id.comments);
    		comments.setText(" Comments ");
    		comments.setOnClickListener(new View.OnClickListener() {
    			@Override
    			public void onClick(View view) {
    				// creating new product in background thread
    				new LoadAllComments().execute();
    			}
    		});
    
    		reportedComments = (Button) rootView
    				.findViewById(R.id.reportedcomments);
    		reportedComments.setText(" Reported comments ");
    		reportedComments.setOnClickListener(new View.OnClickListener() {
    			@Override
    			public void onClick(View view) {
    				// creating new product in background thread
    				new LoadReportedComments().execute();
    			}
    		});
    		
    		lv = (ListView) rootView.findViewById(android.R.id.list);
    
    		managementOfComments = (TextView) rootView
    				.findViewById(R.id.managementofcomments);
    		managementOfComments.setText("Management of comments");
    
    		return rootView;
    	}
    
    	/**
    	 * Background Async Task to Load all comments by making HTTP Request
    	 * */
    	class LoadAllComments extends AsyncTask<String, String, String> {
    
    		/**
    		 * 1 Before starting background thread Show Progress Dialog
    		 * */
    		@Override
    		protected void onPreExecute() {
    			super.onPreExecute();
    			commentsList.clear();
    			pDialog = new ProgressDialog(getActivity());
    			pDialog.setMessage("Loading comments. Please wait...");
    			pDialog.setIndeterminate(false);
    			pDialog.setCancelable(false);
    			pDialog.show();
    		}
    
    		/**
    		 * getting All comments from url
    		 * */
    		protected String doInBackground(String... args) {
    			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
    					.permitAll().build();
    			StrictMode.setThreadPolicy(policy);
    			// Building Parameters
    			List<NameValuePair> params = new ArrayList<NameValuePair>();
    			// getting JSON string from URL
    			JSONObject json = jParser.makeHttpRequest(url_all_comments, "GET",
    					params);
    
    			// Check your log cat for JSON reponse
    			Log.d("All comments: ", json.toString());
    
    			try {
    				// Checking for SUCCESS TAG
    				int success = json.getInt(TAG_SUCCESS);
    
    				if (success == 1) {
    					// comments found
    					// Getting Array of Comments
    					comment = json.getJSONArray(TAG_COMMENTS);
    
    					// looping through All Comments
    					for (int i = 0; i < comment.length(); i++) {
    						JSONObject c = comment.getJSONObject(i);
    
    						// Storing each json item in variable
    						String id = c.getString(TAG_ID);
    						String content = c.getString(TAG_CONTENT);
    						String login = c.getString(TAG_LOGIN);
    
    						// creating new HashMap
    						HashMap<String, String> map = new HashMap<String, String>();
    
    						// adding each child node to HashMap key => value
    						map.put(TAG_ID, id);
    						map.put(TAG_CONTENT, content);
    						map.put(TAG_LOGIN, login);
    
    						// adding HashList to ArrayList
    						commentsList.add(map);
    					}
    				}
    			} 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
    			getActivity().runOnUiThread(new Runnable() {
    				public void run() {
    					/**
    					 * Updating parsed JSON data into ListView
    					 * */
    					ListAdapter adapter = new SimpleAdapter(getActivity(),
    							commentsList, R.layout.list_comment, new String[] {
    									TAG_ID, TAG_CONTENT, TAG_LOGIN },
    							new int[] { R.id.id, R.id.content, R.id.login });
    				    lv.setAdapter(adapter);
    
    					}
    			});
    
    		}
    
    	}
    
    	/**
    	 * Background Async Task to Load all comments by making HTTP Request
    	 * */
    	class LoadReportedComments extends AsyncTask<String, String, String> {
    
    		/**
    		 * 1 Before starting background thread Show Progress Dialog
    		 * */
    		@Override
    		protected void onPreExecute() {
    			super.onPreExecute();
    			commentsList.clear();
    			pDialog = new ProgressDialog(getActivity());
    			pDialog.setMessage("Loading comments. Please wait...");
    			pDialog.setIndeterminate(false);
    			pDialog.setCancelable(false);
    			pDialog.show();
    		}
    
    		/**
    		 * getting All comments from url
    		 * */
    		protected String doInBackground(String... args) {
    			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
    					.permitAll().build();
    			StrictMode.setThreadPolicy(policy);
    			// Building Parameters
    			List<NameValuePair> params = new ArrayList<NameValuePair>();
    			// getting JSON string from URL
    			JSONObject json = jParser.makeHttpRequest(url_comments_reported,
    					"GET", params);
    
    			// Check your log cat for JSON reponse
    			Log.d("Reported comments: ", json.toString());
    
    			try {
    				// Checking for SUCCESS TAG
    				int success = json.getInt(TAG_SUCCESS);
    
    				if (success == 1) {
    					// comments found
    					// Getting Array of Comments
    					comment = json.getJSONArray(TAG_COMMENTS);
    
    					// looping through All Comments
    					for (int i = 0; i < comment.length(); i++) {
    						JSONObject c = comment.getJSONObject(i);
    
    						// Storing each json item in variable
    						String id = c.getString(TAG_ID);
    						String content = c.getString(TAG_CONTENT);
    						String login = c.getString(TAG_LOGIN);
    
    						// creating new HashMap
    						HashMap<String, String> map = new HashMap<String, String>();
    
    						// adding each child node to HashMap key => value
    						map.put(TAG_ID, id);
    						map.put(TAG_CONTENT, content);
    						map.put(TAG_LOGIN, login);
    
    						// adding HashList to ArrayList
    						commentsList.add(map);
    					}
    				}
    			} 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
    			getActivity().runOnUiThread(new Runnable() {
    				public void run() {
    					/**
    					 * Updating parsed JSON data into ListView
    					 * */
    
    					ListAdapter adapter = new SimpleAdapter(getActivity(),
    							commentsList, R.layout.list_comment, new String[] {
    									TAG_ID, TAG_CONTENT, TAG_LOGIN },
    							new int[] { R.id.id, R.id.content, R.id.login });
    				    lv.setAdapter(adapter);
    				}
    			});
    		}
    	}
    }


    et les erreurs :


    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
    06-08 10:54:13.030: W/dalvikvm(2774): threadid=1: thread exiting with uncaught exception (group=0xb3a8dba8)
    06-08 10:54:13.060: E/AndroidRuntime(2774): FATAL EXCEPTION: main
    06-08 10:54:13.060: E/AndroidRuntime(2774): Process: jordan.map, PID: 2774
    06-08 10:54:13.060: E/AndroidRuntime(2774): java.lang.NullPointerException
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at admin.AdminCommentFragment$LoadAllComments.onPreExecute(AdminCommentFragment.java:109)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.os.AsyncTask.execute(AsyncTask.java:535)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at admin.AdminCommentFragment$1.onClick(AdminCommentFragment.java:74)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.view.View.performClick(View.java:4438)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.view.View$PerformClick.run(View.java:18422)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.os.Handler.handleCallback(Handler.java:733)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.os.Handler.dispatchMessage(Handler.java:95)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.os.Looper.loop(Looper.java:136)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at java.lang.reflect.Method.invokeNative(Native Method)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at java.lang.reflect.Method.invoke(Method.java:515)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    06-08 10:54:13.060: E/AndroidRuntime(2774): 	at dalvik.system.NativeStart.main(Native Method)


    Merci

Discussions similaires

  1. JSP avec comme résultat de requête en XML.
    Par Kagome dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 23/04/2008, 17h42
  2. Réponses: 7
    Dernier message: 26/09/2005, 17h50
  3. table comme résultat de requête
    Par nafnaf625 dans le forum Langage SQL
    Réponses: 3
    Dernier message: 10/05/2005, 11h51
  4. Comparaison de résultats de requêtes
    Par Nyx de Tours dans le forum Requêtes
    Réponses: 7
    Dernier message: 31/07/2004, 15h49
  5. Trier aléatoirement un résultat de requête
    Par ang36 dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 08/01/2004, 17h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo