2016-11-14 97 views
0

我在我的應用程序中使用了Autocompletetextview並且它工作正常,但我還需要一件事,即用戶在我的autocompletetextview中輸入的字母應該出現在color.please中,我應該在代碼中添加什麼因此,它會告訴我,我想......這裏是我的代碼AutoCompleteTextView中的顏色如何在AutoCompleteTextView中顯示顏色

class afficheclient extends AsyncTask<String, String, String> { 
 
     InputStream is = null; 
 
     String result = null; 
 
     String line = null; 
 

 
     /** 
 
     * Override this method to perform a computation on a background thread. The 
 
     * specified parameters are the parameters passed to {@link #execute} 
 
     * by the caller of this task. 
 
     * <p/> 
 
     * This method can call {@link #publishProgress} to publish updates 
 
     * on the UI thread. 
 
     * 
 
     * @param params The parameters of the task. 
 
     * @return A result, defined by the subclass of this task. 
 
     * @see #onPreExecute()  * @see #onPostExecute 
 
     * @see #publishProgress 
 
     */ 
 

 
     @Override 
 
     protected String doInBackground(String... params) { 
 
      return null; 
 
     } 
 

 
     @Override 
 
     protected void onPreExecute() { 
 
      super.onPreExecute(); 
 

 

 
      try { 
 
       HttpClient httpclient = new DefaultHttpClient(); 
 
       HttpPost httppost = new HttpPost("http://192.168.1.16/toutclient.php"); 
 
       HttpResponse response = httpclient.execute(httppost); 
 
       HttpEntity entity = response.getEntity(); 
 
       is = entity.getContent(); 
 
       Log.e("Pass 1", "connection success "); 
 
      } catch (Exception e) { 
 
       Log.e("Fail 1", e.toString()); 
 
       Toast.makeText(getApplicationContext(), "Invalid IP Address", 
 
         Toast.LENGTH_LONG).show(); 
 
      } 
 

 
      try { 
 
       BufferedReader reader = new BufferedReader 
 
         (new InputStreamReader(is, "iso-8859-1"), 8); 
 
       StringBuilder sb = new StringBuilder(); 
 

 
       while ((line = reader.readLine()) != null) { 
 
        sb.append(line + "\n"); 
 
       } 
 

 
       is.close(); 
 
       result = sb.toString(); 
 
       Log.e("Pass 2", "connection success "); 
 
      } catch (Exception e) { 
 
       Log.e("Fail 2", e.toString()); 
 
      } 
 

 
      try { 
 
       JSONArray JA = new JSONArray(result); 
 
       JSONObject json = null; 
 
       final String[] str1 = new String[JA.length()]; 
 

 
       for (int i = 0; i < JA.length(); i++) { 
 
        json = JA.getJSONObject(i); 
 
        str1[i] = json.getString("D_CLIENT"); 
 
       } 
 

 
       final AutoCompleteTextView text = (AutoCompleteTextView) 
 
         findViewById(R.id.autoComplete1); 
 
       final List<String> list = new ArrayList<String>(); 
 

 
       for (int i = 0; i < str1.length; i++) { 
 
        list.add(str1[i]); 
 
       } 
 

 
       Collections.sort(list); 
 

 
       ArrayAdapter<String> dataAdapter = new ArrayAdapter<String> 
 
         (getApplicationContext(), android.R.layout.simple_spinner_item, list); 
 

 
       dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
 
       text.setThreshold(1); 
 
       text.setAdapter(dataAdapter); 
 

 
       text.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
 

 
        @Override 
 
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { 
 
         // TODO Auto-generated method stub 
 
        //  Toast.makeText(getBaseContext(), list.get(arg2).toString(), 
 
           // Toast.LENGTH_SHORT).show(); 
 
        } 
 
       }); 
 
      } catch (Exception e) { 
 
       Log.e("Fail 3", e.toString()); 
 
      } 
 
     } 
 
    }

+1

請指定你想要的內容並試着重新修改你的問題 –

+0

我想要的是當我找到包含我尋找的字母的數據列表時,顯示除了以彩色輸入的字母之外的所有正常句子,我希望我更清楚:) – jasmine

回答

0

你想顯示在自動建議的顏色嗎?在Asynctask中,您應該首先執行OnPreExecute方法。之後,url的所有後臺工作都應在doinbackground方法內。