Android搜索框自动提示文本框——(多次提示)
程序员文章站
2022-07-14 17:57:33
...
MultiAutoCompleteTextView(多次提示)
//设置多次提示时用分隔符隔开方法,
默认为逗号,要想设置为其他的分隔符
https://blog.csdn.net/waz929/article/details/83503101
MultiAutoCompleteTextView.Tokenizer t = new MultiAutoCompleteTextView.CommaTokenizer();
mactv_main.setTokenizer(t);
package com.example.android_06;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
// 高级控件搜索提示框(多次提示)
private String[] data4;
private ArrayAdapter adapter4;
private MultiAutoCompleteTextView mactv_main_context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
* 高级控件搜索提示框(多次提示)(作业)
*/
data4 = new String[]{ "愤怒的小鸟", "汤姆猫", "落汤鸡", "牛牛", "哈巴狗", "神龙", "烤鸭", "小象", "美人鱼", "九尾狐" };
adapter4 = new ArrayAdapter(this,R.layout.actv_main_item1,data4);
MultiAutoCompleteTextView.Tokenizer t = new MultiAutoCompleteTextView.CommaTokenizer();
mactv_main_context.setTokenizer(t);
mactv_main_context.setAdapter(adapter4);
}
/**
* 初始化
*/
public void initView(){
actv_main_context = findViewById(R.id.actv_main_context);
spinner_main_img = findViewById(R.id.spinner_main_img);
mactv_main_context = findViewById(R.id.mactv_main_context);
}
}