我正在尝试使用自动填充文本,但我遇到了一个小问题。
当我尝试输入第一个单词作为其中一个国家时,它工作正常, 但如果我尝试输入任何其他东西,然后其中一个国家没有任何反应,例如:“ger”(将给我德国)和:“hello ger”(不会给德国)
如果我只点击一次输入并从第二行开始,同样的事情就会发生,它只适用于第一个单词和第一行。另外,如果我确实将它用于第一个单词并尝试再次使用它,例如德国(来自自动完成),然后输入 ger ,则不会弹出任何内容。
知道如何使其适用于文本的其余部分或如何控制它(将其设置为选中或放置在一行之后?
代码:
AutoCompleteTextView et1;
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
et1=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
et1.setAdapter(adapter);
et1.setThreshold(0);
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.asaf1.workersreports.Main3Activity">
<AutoCompleteTextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/autoCompleteTextView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:textAlignment="viewEnd"
android:gravity="right|top"/>
</RelativeLayout>
答案 0 :(得分:1)
增加你的门槛值以获得......的建议
如果您想在1st character
之后进行搜索,那么
et1.setThreshold(1);
如果您想在2nd character
之后进行搜索,那么
et1.setThreshold(2);
答案 1 :(得分:0)
You have to create custom AutoCompleteTextView
. In Adapter
implement the Filter class and and override performFilterring()
method. In this method you have to write some code which matches the result. In your case you have to check for input string contains the one of your list of strings.
Check this links where custom Adapter is used: Custom AutoCompleteTextView behavior and AutoCompleteTextView backed by CursorLoader