• 小技巧按菜单键 当菜单打开之前会调用onMenuOpened(int featereId,Menu menu),可以重写这个方法,弹出对话框或者Popmenu
  1. 再布局中添加控件AutoCompleteTextView.
 <AutoCompleteTextView
        android:id="@+id/at"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="1"/>
  1. 显示数据原理和listView一样需要数据适配器adapter
  2. 显示数据setAdapter()方法
  • 属性completionThreshold 后面接收一个int类型 对应方法 setThreshold(int)默认是两个字符才开始提示 可以用这个设置成1个就提示。
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       AutoCompleteTextView autoCompleteTextView= findViewById(R.id.at);
       //       autoCompleteTextView.setThreshold(1);
	   String[] country={"ss","dd","dfgd","wa","sd","fgr","ss1","dd2","dfgd3","wa1","sd2","fgr2"};
        ArrayAdapter<String> myAdapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line, country);
        autoCompleteTextView.setAdapter(myAdapter);
    }
}
10-16 00:39