Salut a tous,


Voila je travail sur une fonction qui pourrais me permettre d'afficher les résultats d'un mot rechercher.
mais voila les informations ne me sont pas retournée voila mes fichiers:

Si une personne a une idée du problème serait très Yahoo !!!

Code:

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
<?php require 'connexion.php'; ?>
 
<?php 
		$response = array();
 
	    ////////////////////////////////////////////////
		//Executer la requete d'affichage
		////////////////////////////////////////////////
 
		$keyword = $_GET["keyword"];
 
		$result = mysql_query("SELECT nom FROM contact WHERE nom LIKE '%$keyword%' LIMIT 0, 20") or die(mysql_error());
 
		if(mysql_num_rows($result) > 0){ 
 
			$response["contact"] = array();
 
				while($row = mysql_fetch_array($result)){
 
					$personne = array();
					$personne["idCONTACT"] = $row["idCONTACT"];
					$personne["nom"] = $row["nom"];
					$personne["prenom"] = $row["prenom"];
					$personne["numero_mobile"] = $row["numero_mobile"];
					$personne["numero_fixe"] = $row["numero_fixe"];
					$personne["email"] = $row["email"];
					$personne["adresse"] = $row["adresse"];
					$personne["profession"] = $row["profession"];
 
					array_push($response["contact"], $personne);
				}
 
				$response["success"] = 1;
    			echo json_encode($response);
		}
 
			else{
	    		$response["success"] = 0;
	    		$response["message"] = "Contact non Trouve !";
	    		echo json_encode($response);
	    	}
 ?>
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
public class ListResult extends ListActivity {
 
	// attribut Chargement
    private ProgressDialog pDialog;
 
    // Creation dun objet Jsonparser
    JSONParser jParser = new JSONParser();
 
    ArrayList<HashMap<String, String>> contactList;
 
	//  url permettant de retourner tous la liste des contacts
	private static String url_search = "http://10.0.2.2/contactCloud/search_contact.php";//"http://10.0.2.2/contactCloud/list_contact.php"
 
 
    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_CONTACT = "contact";
    private static final String TAG_IDCONTACT = "idCONTACT";
    private static final String TAG_NOM = "nom";
 
    // contacts JSONArray
    JSONArray contacts = null;
    //search key value
    public String searchkey;
 
    ///////////////////////////////////////////////////////////////////////////////////////
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_result);
 
        Intent myIntent = getIntent();
        // gets the arguments from previously created intent
        searchkey = myIntent.getStringExtra("keyword"); 
 
 
        // Hashmap d'une ListView
        /* Une collection de type Map est une collection qui fonctionne avec un couple clé - valeur.
         * La clé, qui sert à identifier une entrée dans notre collection, est unique. 
         * La valeur, au contraire, peut être associée à plusieurs clés.
         * */
        contactList = new ArrayList<HashMap<String, String>>();
 
        // Charges les contacts en Background Thread
        new LoadAllContacts().execute();
 
        // Retourne la listview
        ListView lv = getListView();
 
        /* Selection d'un seul contact
         * Lancement de la vue MajContactActivity
         * Ici on place un écouteur sur l'élément sélectionné. 
         * La méthode onItemClick() donne 4 arguments. 
         * Le troisième “int position”, est le seul qui nous intéresse, puisqu'il donne le numéro de l'élément cliqué dans la liste. 
         * */
        lv.setOnItemClickListener(new OnItemClickListener() {
 
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //retourne les valeur de la  ListItem selectionner
                String iidCONTACT = ((TextView) view.findViewById(R.id.idCONTACT)).getText().toString();
 
            }
        });
        }
 
 
 
        /**
         * Background Async Task tous les contact en faisant HTTP Request
         * */
        class LoadAllContacts extends AsyncTask<String, String, String> {
 
            /**
             * Avant de commencer en background thread affiche la Progress Dialog
             * */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(ListResult.this);
                pDialog.setMessage("Chargement des contacts. Patienter...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();
            }
 
 
            /**
             * retourne tous les contacts via l'url
             * */
            protected String doInBackground(String... args) {
 
            	// Construction des parametre
                List<NameValuePair> params = new ArrayList<NameValuePair>();
 
                params.add(new BasicNameValuePair("keyword", searchkey)); 
 
                // retourne la chaine de caractere en json via l'url
                JSONObject json = jParser.makeHttpRequest(url_search, "GET", params);
 
                // Affiche dans les logcat la response en json
                Log.d("Cherche le contact: ", json.toString());
 
                try {
                	// vérifie si tous a bien reussi
                    int success = json.getInt(TAG_SUCCESS);
 
                    if (success == 1) {
                        // contacts found
                        // retourne le tableau de contact
                        contacts = json.getJSONArray(TAG_CONTACT);
 
                        // bouclage de tous les contacts
                        for (int i = 0; i < contacts.length(); i++) {
                            JSONObject c = contacts.getJSONObject(i);
 
                            // Stockage de chaque élément JSON dans la variable
                            String id = c.getString(TAG_IDCONTACT);
                            String nom = c.getString(TAG_NOM);
 
                            //Creation d'un nouveau HashMap
                            HashMap<String, String> map = new HashMap<String, String>();
 
                            // ajoute chaque noeud enfant de la HashMap key => value
                            map.put(TAG_IDCONTACT, id);
                            map.put(TAG_NOM, nom);
 
                            // ajoutan HashList à ArrayList
                            contactList.add(map);
                        }
                    } else {
                        // aucun contact trouver
                        // Lancement de l'ajoute d'un nouveau contact a l'activity
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
 
                return null;
            }
 
            /**
             * Après avoir terminé en Background enlever le dialogue de progression
             * **/
            protected void onPostExecute(String file_url) {
            	// renvoie le dialogue après avoir retourne tous les contacts
                pDialog.dismiss();
 
                //Déposer le Runnable dans la file d'attente de l'UI thread
                runOnUiThread(new Runnable() {
                    public void run() {
                    	//code exécuté par l'UI thread
                        /**
                         * Mise à jour des données analyser du JSON dans ListView
                         * */
                    ListAdapter adapter = new SimpleAdapter(
                    		ListResult.this, contactList, 
                    		R.layout.list_item, new String[] { TAG_IDCONTACT, TAG_NOM}, 
                        	new int[] { R.id.idCONTACT, R.id.nom });
                        // mise a jour de la listview
                        setListAdapter(adapter);
                    }
                });
 
            }
 
        }
}

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
public class SearchContact extends Activity implements OnClickListener{
 
	private EditText txtkeyword;
	private Button btnsearch;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_contact);
 
		//link to UI
		txtkeyword=(EditText)findViewById(R.id.txtkeyword);
		btnsearch=(Button)findViewById(R.id.btnsearch);
		btnsearch.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) {
		if(v.getId()==R.id.btnsearch){
			Intent searchIntent = new Intent(this, ListResult.class);
			//send the keyword to the next screen
			searchIntent.putExtra("key",txtkeyword.getText().toString());
			//call the screen for listing
			startActivity(searchIntent);
		}
	}
 
}
XML:
Search_contact.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
<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=".Search" >
 
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
 
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
 
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Recherche par nom:"
    android:textAppearance="?android:attr/textAppearanceLarge" />
 
</TableRow>
 
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
 
<EditText
android:id="@+id/txtkeyword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
 
<requestFocus />
</EditText>
 
</TableRow>
 
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
 
<Button
    android:id="@+id/btnsearch"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Recherche" />
 
</TableRow>
 
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
 
</RelativeLayout>
list_result.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
<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=".ListResult" >
 
		<!-- Main ListView
		Always give id value as list(@android:id/list)
		-->
		<ListView
		android:id="@android:id/list"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"/>
 
</RelativeLayout>

AndroidManifest.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
<!-- Recherche Contact Activity -->
        <activity
            android:name=".ListResult"
            android:label="Tous les contacts" >
        </activity>
 
        <activity
            android:name=".SearchContact"
            android:label="Recherche les contacts" >
        </activity>


Erreur:
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
05-01 18:13:46.747: E/JSON Parser(1177): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
05-01 18:13:52.007: W/dalvikvm(1177): threadid=11: thread exiting with uncaught exception (group=0xb3ab7ba8)
05-01 18:13:57.737: E/AndroidRuntime(1177): FATAL EXCEPTION: AsyncTask #1
05-01 18:13:57.737: E/AndroidRuntime(1177): Process: fr.paris8.contactcloud, PID: 1177
05-01 18:13:57.737: E/AndroidRuntime(1177): java.lang.RuntimeException: An error occured while executing doInBackground()
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at android.os.AsyncTask$3.done(AsyncTask.java:300)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at java.util.concurrent.FutureTask.run(FutureTask.java:242)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at java.lang.Thread.run(Thread.java:841)
05-01 18:13:57.737: E/AndroidRuntime(1177): Caused by: java.lang.NullPointerException
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at fr.paris8.contactcloud.ListResult$LoadAllContacts.doInBackground(ListResult.java:128)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at fr.paris8.contactcloud.ListResult$LoadAllContacts.doInBackground(ListResult.java:1)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-01 18:13:57.737: E/AndroidRuntime(1177): 	... 4 more
05-01 18:14:10.327: E/WindowManager(1177): android.view.WindowLeaked: Activity fr.paris8.contactcloud.ListResult has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{b3de2108 V.E..... R.....ID 0,0-480,144} that was originally added here
05-01 18:14:10.327: E/WindowManager(1177): 	at android.view.ViewRootImpl.<init>(ViewRootImpl.java:348)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.Dialog.show(Dialog.java:286)
05-01 18:14:10.327: E/WindowManager(1177): 	at fr.paris8.contactcloud.ListResult$LoadAllContacts.onPreExecute(ListResult.java:110)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.os.AsyncTask.execute(AsyncTask.java:535)
05-01 18:14:10.327: E/WindowManager(1177): 	at fr.paris8.contactcloud.ListResult.onCreate(ListResult.java:71)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.Activity.performCreate(Activity.java:5231)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.os.Handler.dispatchMessage(Handler.java:102)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.os.Looper.loop(Looper.java:136)
05-01 18:14:10.327: E/WindowManager(1177): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
05-01 18:14:10.327: E/WindowManager(1177): 	at java.lang.reflect.Method.invokeNative(Native Method)
05-01 18:14:10.327: E/WindowManager(1177): 	at java.lang.reflect.Method.invoke(Method.java:515)
05-01 18:14:10.327: E/WindowManager(1177): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-01 18:14:10.327: E/WindowManager(1177): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-01 18:14:10.327: E/WindowManager(1177): 	at dalvik.system.NativeStart.main(Native Method)