我在我的应用程序中使用了Autocompletetextview并且效果很好,但我还想要一件事,用户在我的autocompletetextview中输入的字母应该出现在color.please中,我应该在代码中添加什么以便它显示我想要的......这是我的代码
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());
}
}
}
答案 0 :(得分:0)
您想在自动建议中显示颜色吗?在Asynctask中你应该先执行OnPreExecute方法。之后url的所有后台工作都应该在doinbackground方法中。