2016-11-14 75 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方法内。

相关问题