Android搜索框自动提示文本框——(单一提示)
程序员文章站
2022-03-08 11:39:21
...
AutoCompleteTextView(单一提示)
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[] data1;//数据源
//ArrayAdapter数组适配器
private ArrayAdapter adapter1;//定义适配器
private AutoCompleteTextView actv_main_context;//定义高级控件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
* 高级控件搜索提示框(单一提示)
*/
initView();
data1 = new String[]{ "愤怒的小鸟", "汤姆猫", "落汤鸡", "牛牛", "哈巴狗", "神龙", "烤鸭","小象", "美人鱼", "九尾狐" };
adapter1 = new ArrayAdapter(this,R.layout.actv_main_item1,data1);
actv_main_context.setAdapter(adapter1);
}
/**
* 初始化
*/
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);
}
}
下一篇: 页面延迟跳转Handler实现