Android多提示的自动补全
扫描二维码
随时随地手机看文章
在activity_main.xml中写
在MainActivity.java中写
package pw.gutao.android_08_0628; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.MultiAutoCompleteTextView; public class MainActivity extends AppCompatActivity { private AutoCompleteTextView autoCompleteTextView; private MultiAutoCompleteTextView multiAutoCompleteTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取多提示的自动补全的文本框 multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.mctv_main_1); //获取数组 String[] data = getResources().getStringArray(R.array.str_data); //将数据放入文本框 //使用适配器 数组适配器(使用自己的layout R.layout.complete_layout) ArrayAdapter adapter = new ArrayAdapter(this,R.layout.complete_layout,data); //设置通过","号作为区分一依据(comma逗号) MultiAutoCompleteTextView.Tokenizer tokenizer = new MultiAutoCompleteTextView.CommaTokenizer(); //给multiAutoCompleteTextView设置区分依据 multiAutoCompleteTextView.setTokenizer(tokenizer); //将适配器设置给控件 multiAutoCompleteTextView.setAdapter(adapter); } }