Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Android中自动完成文本?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的应用程序中,我使用的是自动完成文本.当用户键入t时,它显示三,二,五十,但我想显示二,三不五十.任何人都可以帮我解决这个问题.
String search[] = {"one","two","three","four","five","six","seven","fifty"};    

ArrayAdapter<String> adp= new ArrayAdapter<String>(this,R.layout.searchtext,search);
    search_item.setThreshold(1);
    search_item.setAdapter(adp);

解决方法

我认为你不必创建自定义适配器.它所需的功能.检查一下

这里我有像这样的数组:

private static final String[] COUNTRIES = new String[] { "Belgium","France","France_","Italy","GeRMANy","Spain","abcf","FFa","FFb","bFF","aFF" };

当我搜索ff然后它只给我2(“FFa”,“FFb”)建议不是4(“FFa”,“FFb”,“bFF”,“aFF”)

我在ActionBar中使用过它.你也可以在布局中使用它.因为它在ActionBar中的自定义布局.

public class TestActivity extends Activity {

    /** Called when the activity is first created. */
    private static final String[] COUNTRIES = new String[] { "Belgium","aFF" };

    @Override
    public void onCreate(Bundle savedInstanceStatE) {
        super.onCreate(savedInstanceStatE);

        setContentView(R.layout.activity_main);

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
        // actionBar.setDisplayShowtitleEnabled(false);
        // actionBar.setIcon(R.drawable.ic_action_search);

        LayoutInflater inflator = (LayoutInflater) this
                .getSy@L_673_12@service(Context.LAYOUT_INFLATER_serviCE);
        View v = inflator.inflate(R.layout.test,null);

        actionBar.setCustomView(v);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,COUNTRIES);
        AutoCompleteTextView textView = (AutoCompleteTextView) v
                .findViewById(R.id.editText1);
        textView.setAdapter(adapter);

    }
}

的test.xml

<LinearLayout xmlns:android="http://scheR_245_11845@as.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Action Bar:"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFFFFF" />

    <AutoCompleteTextView
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:imeOptions="actionSearch"
        android:inputType="textAutoComplete|textAutoCorrect"
        android:textColor="#FFFFFF" >

        <requestFocus />
    </AutoCompleteTextView>

</LinearLayout>

大佬总结

以上是大佬教程为你收集整理的在Android中自动完成文本?全部内容,希望文章能够帮你解决在Android中自动完成文本?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。