UI控件--AutoCompleteTextView

AutoCompleteTextView

  • 带有提示的搜索栏
  • 首先在布局文件中添加该控件
.support.v7.widget.AppCompatAutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/autoCompleteTextView"
        android:hint="请输入要查询的内容。。。"/>
  • AutoCompleteTextView的使用也是同ArrayAdapter一起,所以基本用法和listView的适配基本一致
public class MainActivity extends AppCompatActivity {

    private AutoCompleteTextView textView;
    private String[] data={"layout","layout_oo","lay?","laynishi嘛的!!!"};
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ArrayAdapter arrayAdapter=new ArrayAdapter(getApplicationContext(),android.R.layout.simple_list_item_1,data);
        textView= (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
        textView.setAdapter(arrayAdapter);


    }
}
  • 效果如图
    UI控件--AutoCompleteTextView_第1张图片

你可能感兴趣的:(Android)