Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Dynamic Autocomplete don't show
    primarykey
    data
    text
    <p>i need help with my code, i try to implement aoutocomplete textview but don't work.</p> <p>i used a asyntask and a httpclient to catch the info from google.</p> <p>My code is:</p> <p>public class MainActivity extends Activity {</p> <pre><code>AutoCompleteTextView text_search; ArrayAdapter&lt;String&gt; adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text_search = (AutoCompleteTextView)this.findViewById(R.id.tx_search); ArrayList&lt;String&gt; entries = new ArrayList&lt;String&gt;(Arrays.asList("Dowgo")); adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, entries); text_search.setAdapter(adapter); text_search.setThreshold(1); adapter.setNotifyOnChange(true); text_search.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { new AsyncTask&lt;String,Void,String[]&gt;(){ @Override protected void onPreExecute() { text_search.setAdapter(null); } @Override protected String[] doInBackground(String... strings) { int lon = strings.length; if (lon&lt;1) return null; String busqueda = strings[0]; String url = "http://clients1.google.com/complete/search"; if (busqueda.length() &lt; 2) return null; HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0"); if(!url.endsWith("?")) url += "?"; List&lt;NameValuePair&gt; params = new LinkedList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("q", busqueda)); params.add(new BasicNameValuePair("nolabels", "t")); params.add(new BasicNameValuePair("client", "youtube")); params.add(new BasicNameValuePair("ds", "yt")); String paramString = URLEncodedUtils.format(params, "utf-8"); url += paramString; HttpGet httpget = new HttpGet(url); //httpget.addHeader("Accept-Language", "es"); ArrayAdapter adaptador; try { // Execute HTTP Post Request HttpResponse response = httpclient.execute(httpget); if(response.getStatusLine().getStatusCode() != 200) return null; HttpEntity resEntityGet = response.getEntity(); String respuesta = EntityUtils.toString(resEntityGet); respuesta = respuesta.substring(respuesta.indexOf("[["), respuesta.indexOf("]]") + 2); String[] resultados = respuesta.split(","); int lens = 0; if(resultados.length%2==0) lens = resultados.length/2; else lens = (resultados.length-1)/2; String[] sugeridos = new String[lens]; int con = 0; for(int x=0;x&lt;resultados.length-1;x+=2){ sugeridos[con] = resultados[x].replace("[","").replace("\"",""); con++; } Log.d("Respuesta",respuesta); return sugeridos; } catch (ClientProtocolException e) { return null; } catch (IOException e) { return null; } } @Override protected void onPostExecute(String[] result) { if (result != null){ adapter.clear(); for(int x=0;x&lt;result.length;x++) { adapter.add(result[x]); } adapter.notifyDataSetChanged(); text_search.showDropDown(); }else{ adapter.clear(); adapter.notifyDataSetChanged(); } } }.execute(charSequence.toString()); } @Override public void afterTextChanged(Editable editable) { } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } </code></pre> <p>}</p> <p>thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload