jasmine jasmine - 20 days ago 9
Java Question

how affiche color in AutoCompleteTextView

hy , I use a Autocompletetexteview in my application And it works well, but I want to add a more: it is that the letters entered in my autocompletetextview appears in color in the result display.please, what should I add so that it will show me as I want......Here is my code



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());
}
}
}




Answer

Are you want to show color in auto suggestions? In Asynctask you should first execute OnPreExecute method.After that all the back work of url should inside doinbackground method.

Comments