当我input第一个字符时,AutoCompleteTextView不起作用

当我在文本框中input第一个字符时,我的AutoCompleteTextView不起作用,但在input第二个字符时开始显示下拉菜单。 可能是什么原因?

<AutoCompleteTextView android:id="@+id/autocomplete_name" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="7" android:background="@drawable/edittextback" android:ems="10" android:textSize="15sp" android:hint="@string/codehint" android:textColorHint="@color/hintgrey" android:dropDownWidth="fill_parent" android:paddingRight="30dp" android:paddingLeft="10dp" android:singleLine="true" android:ellipsize="end" /> 

Related of "当我input第一个字符时,AutoCompleteTextView不起作用"

EASY:D

您需要将autoCompleteViewcompletionThreshold属性设置为1。

 <AutoCompleteTextView android:id="@+id/someID" android:layout_width="200dp" android:layout_height="wrap_content" android:completionThreshold="1" /> 

或者通过代码使用dynamic地执行

 mAutoCompleteTextView.setThreshold(1) 

快乐编码:)

使用我的Java代码

 autoComplete.setThreshold(1); 

或者在xml中

 android:completionThreshold="1" 
 import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.MultiAutoCompleteTextView; import android.widget.Toast; public class MainActivity extends Activity { private AutoCompleteTextView autoComplete; private MultiAutoCompleteTextView multiAutoComplete; private ArrayAdapter<String> adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // get the defined string-array String[] colors = getResources().getStringArray(R.array.colorList); adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,colors); autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete); multiAutoComplete = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoComplete); // set adapter for the auto complete fields autoComplete.setAdapter(adapter); multiAutoComplete.setAdapter(adapter); // specify the minimum type of characters before drop-down list is shown autoComplete.setThreshold(1); multiAutoComplete.setThreshold(2); // comma to separate the different colors multiAutoComplete.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); // when the user clicks an item of the drop-down list multiAutoComplete.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Toast.makeText(getBaseContext(), "MultiAutoComplete: " + "you add color "+arg0.getItemAtPosition(arg2), Toast.LENGTH_LONG).show(); } }); } }