Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid getting both called: onItemClicked and onTextChanged on AutoCompleteTextView
    primarykey
    data
    text
    <p>I have this code. When I choose an item from suggestion list, the onTextChanged happens first, then oItemClicked comes after that. Now I want when choosing a word, the "onItemClicked" appears first, then "onTextChanged". I took a look Android doc but it doesn't mention this topic.</p> <pre><code>package com.autocompletetest; import java.util.Arrays; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class OnItemClickAndOnTextChangedActivity extends Activity implements TextWatcher, OnItemClickListener { private AutoCompleteTextView textView; private static final String[] TEMP = new String[] { "Beep", "Belgium", "Best", "Bubble", "Bye" }; @Override protected void onCreate(final Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); textView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); textView.setOnItemClickListener(this); textView.addTextChangedListener(this); textView.setThreshold(1); final List&lt;String&gt; list = Arrays.asList(TEMP); final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;( OnItemClickAndOnTextChangedActivity.this, android.R.layout.simple_dropdown_item_1line, list); textView.setAdapter(adapter); } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { System.out.println("OnTextChanged."); } @Override public void onItemClick(final AdapterView&lt;?&gt; parent, final View view, final int position, final long id) { System.out.println("OnItemClick."); } @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override public void afterTextChanged(final Editable s) { } } </code></pre> <p><strong>Update:</strong> In detail, this is real thing I want to do. Something is not related to question title.</p> <pre><code>package com.autocompletetest; import java.util.Arrays; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class OnItemClickAndOnTextChangedActivity extends Activity implements TextWatcher, OnItemClickListener { private AutoCompleteTextView textView; private boolean itemClicked; private static final String[] TEMP = new String[] { "Beep", "Belgium", "Best", "Bubble", "Bye" }; @Override protected void onCreate(final Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); textView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); textView.setOnItemClickListener(this); textView.addTextChangedListener(this); textView.setThreshold(1); final List&lt;String&gt; list = Arrays.asList(TEMP); final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;( OnItemClickAndOnTextChangedActivity.this, android.R.layout.simple_dropdown_item_1line, list); textView.setAdapter(adapter); } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { System.out.println("OnTextChanged."); // The below code block does: // When type a word, make a new ArrayAdapter and set it for textView // If any of word in suggestion list is clicked, nothing changes, dropdown list not shown. if(itemClicked) { itemClicked = false; } else { // Create new ArrayAdapter. // textView is set to new ArrayAdapter. // textView.showDropDown() } } @Override public void onItemClick(final AdapterView&lt;?&gt; parent, final View view, final int position, final long id) { System.out.println("OnItemClick."); itemClicked = true; } @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override public void afterTextChanged(final Editable s) { } } </code></pre>
    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.
 

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