android示例之AutoCompleteTextView
来源:互联网 发布:java http base64 编辑:程序博客网 时间:2024/04/28 23:15
AutoCompleteTextView是用来自动提示或者补全用户的输入的,好处是用户可以减少输入量。
效果图:
使用AutoCompleteTextView的步骤是:
1、设置AutoCompleteTextView的布局;
2、设置用户输入时,提示的内容列表的样式文件;
3、设置数据源和适配器;
4、将AutoCompleteTextView和ArrayAdapter联系起来;
代码:
AutoCompleteTextView的布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="测试"/> <AutoCompleteTextView android:id="@+id/auto" android:layout_width="fill_parent" android:layout_height="wrap_content"/></LinearLayout>
提示内容的样式表的样式:
<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp" android:textColor="#FF4500"/>
Activity中:
public class AutoCompleteTextViewActivity extends Activity {private AutoCompleteTextView auto;//显示提示的数据来源private String[] list={"afa","Afa","afb","afc","afd","afe","aff","afg","afh","afi","bf"};//显示的适配器private ArrayAdapter<String> arrayAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //得到自动输入框架 auto=(AutoCompleteTextView)findViewById(R.id.auto); //得到带有数据源的适配器 arrayAdapter=new ArrayAdapter<String>(this,R.layout.list,list); //把ArrayAdapter设置给AutoCompleteTextView,将自动输入框和适配器联系起来 auto.setAdapter(arrayAdapter); }}
根据结果可以看出,提示列表的数据显示顺序和数据源的提供数据的顺序是一致的。
0 0
- android示例之AutoCompleteTextView
- Android 笔记 之 AutoCompleteTextView
- Android开发之AutoCompleteTextView
- android之autoCompleteTextView
- android之AutoCompleteTextView
- Android--UI之AutoCompleteTextView
- Android之AutoCompleteTextView
- android笔记之autoCompleteTextView
- Android--UI之AutoCompleteTextView
- Android学习之AutoCompleteTextView
- Android控件之AutoCompleteTextView
- Android控件之AutoCompleteTextView
- Android控件之AutoCompleteTextView
- Android UI之AutoCompleteTextView
- Android开发之AutoCompleteTextView
- Android控件之AutoCompleteTextView
- Android控件之AutoCompleteTextView
- AutoCompleteTextView示例
- [职业规划]从工程师到项目经理
- Matlab中使用外部系统命令(如C++编译的exe等)
- ruby on rails install Records @Linux
- 关于json的一些事
- 【容易打工网】实习,第一场午餐跟谁吃?
- android示例之AutoCompleteTextView
- Apple 企业开发者账号&邓白氏码申请记录
- C/C++位运算操作
- poj2350Above Average
- 研究生常用的十八大学术搜索引擎
- 关于php-fpm占用系统资源分析
- 黑马程序员学习笔记——java中的断言
- Hive与Hbase的整合
- nyoj306(走迷宫)