gpt4 book ai didi

android - 如何使 MultiAutoCompleteTextView 搜索子字符串

转载 作者:行者123 更新时间:2023-11-30 03:53:25 26 4
gpt4 key购买 nike

如何让我的 MultiAutoCompleteTextView 在每个列表位置的字符串中搜索(也意味着搜索子字符串)。是否需要设置任何属性或者甚至可能?例如,如果列表对象之一是“abc123”,那么是否可以通过键入 123 将其包含在自动完成建议中?

最佳答案

继续这个链接并尝试这个,

http://android-er.blogspot.in/2010/07/example-of-multiautocompletetextview.html

MultiAutoCompleteTextView is an editable text view, extending AutoCompleteTextView, that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing.

You must must provide a MultiAutoCompleteTextView.Tokenizer to distinguish the various substrings.

主.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<MultiAutoCompleteTextView android:id="@+id/multiautocompletetextview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
/>

Java主要代码:

package com.exercise.AndroidMultiAutoCompleteTextView;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.MultiAutoCompleteTextView;

public class AndroidMultiAutoCompleteTextView extends Activity {

MultiAutoCompleteTextView myMultiAutoCompleteTextView;
String item[]={
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

MultiAutoCompleteTextView myMultiAutoCompleteTextView
= (MultiAutoCompleteTextView)findViewById(
R.id.multiautocompletetextview);

myMultiAutoCompleteTextView.setAdapter(
new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, item));
myMultiAutoCompleteTextView.setTokenizer(
new MultiAutoCompleteTextView.CommaTokenizer());

}
}

关于android - 如何使 MultiAutoCompleteTextView 搜索子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13742878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com