2014-12-04 84 views
0

我有這個代碼來填充一個json查詢的列表視圖,並且工作正常,但我想用一個在edittext中編寫的where查詢來填充該視圖,例如:Select * from tabla where name =(edittext)。Mysql查詢(其中)與edittext android

class AsyncExecute extends AsyncTask<Void, Void, Void>{ 

    @Override 
    protected Void doInBackground(Void... params) { 
     try { 
       // Llamamos al servicio web para recuperar los datos 
       HttpGet httpGet = new HttpGet("http://comupunt.esy.es/nombreb.php"); 
       HttpClient httpClient = new DefaultHttpClient(); 
       HttpResponse response = (HttpResponse)httpClient.execute(httpGet); 
       HttpEntity entity = response.getEntity(); 
       BufferedHttpEntity buffer = new BufferedHttpEntity(entity); 
       InputStream iStream = buffer.getContent(); 

       String aux = ""; 

       BufferedReader r = new BufferedReader(new InputStreamReader(iStream)); 
       StringBuilder total = new StringBuilder(); 
       String line; 
       while ((line = r.readLine()) != null) { 
        aux += line; 
       } 

       // Parseamos la respuesta obtenida del servidor a un objeto JSON  
       JSONObject jsonObject = new JSONObject(aux); 
       JSONArray cities = jsonObject.getJSONArray("cities"); 

       // Recorremos el array con los elementos cities 
       for(int i = 0; i < cities.length(); i++) { 
        JSONObject city = cities.getJSONObject(i); 

        // Creamos el objeto City 
        City c = new City(city.getString("name"), 
       city.getInt("nametwo"),city.getString("posicion")); 
        c.setData(city.getString("photo")); 


        listaPersonas.add(c.photo); 
        // Almacenamos el objeto en el array que hemos creado anteriormente 
        citiesAvaiable.add(c); 

       } 
       } 
       catch(Exception e) { 
       e.printStackTrace(); 
       } 
     return null; 
    } 
+0

你把'JSONObject'到數據庫? MySql查詢假設你有一個數據庫,但你沒有顯示。 – 2014-12-04 21:12:46

回答

0

嘗試這樣的事情

String mEditText = (EditText)findViewById(R.id.edittext); 
String EditTextValue = mEditText.getText.toString(); 

然後通過這個EditTextValue在條件

+0

那麼,如何將一個變量傳遞給json? – 2014-12-04 21:47:50