Note that there are some explanatory texts on larger screens.

plurals
  1. POAutocompletion delay
    primarykey
    data
    text
    <p>I've got to set an autocompletion for my application.</p> <p>I've already understood the AutoCompleteTextView operation, but I'd like to dynamically modify the <code>String[]</code> used by android autocompletion.</p> <p>What I wanna do : call a PHP page which will give me a <code>String[]</code> that I'll use in my AutoCompleteTextView, but i wanna do that ONLY if a key was pressed at least 500 milliseconds after the last one.</p> <hr> <h1>EDIT :</h1> <p>Okay, I was wrong. I want to have my asynctask running if NO KEY is pressed in the 500 milliseconds after the last press (you know, avoiding overcharging our servers by calling a request on every character typed in.)</p> <hr> <p>Here is how I think I'll do :</p> <pre><code>zipBox.setAdapter(myAdapter); //zipBox is an AutoCompleteTextView zipBox.addTextChangedListener(new TextWatcher(){ @Override public void onTextChanged(CharSequence s, int start, int before, int count){ d = new Date(); GetAutocompletion ac = new GetAutocompletion(); ac.execute(zipBox.getText().toString()); } // Other methods to implement }); private class GetAutocompletion extends AsyncTask&lt;String, String, String&gt;{ @Override protected String doInBackground(String... params){ //adapter.notifyDataSetChanged(); try{ wait(500); } catch(InterruptedException e){} Date d1 = new Date(); if(d1.getTime() - d.getTime() &gt; 500){ String res = ""; try{ URLConnection conn = new URL("myUrl.php?term=" + params[0]).openConnection(); InputStream in = conn.getInputStream(); Scanner s = new Scanner(in).useDelimiter("\\A"); while (s.hasNext()) res += s.next(); s.close(); in.close(); } catch(Exception e){ Log.d("eduine", "error during autocompletion receive"); } return json; } else return null; } @Override protected void onPostExecute(String result){ super.onPostExecute(result); Log.d("eduine", "json result : " + result); } } </code></pre> <p>What do you think? Is there anyway I could use Timer class?</p>
    singulars
    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