android之AutoCompleteTextView控件用法
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.example.mar_2300_autocompletetextview.MainActivity"
tools:ignore="MergeRootFrame" >
<AutoCompleteTextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/atv"/>
<TextView android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Mar_2300_AutoCompleteTextView</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string> <string-array name="test">
<item>Mercury</item>
<item>Mercury2</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array> </resources>
package com.example.mar_2300_autocompletetextview; import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
import android.os.Build; public class MainActivity extends Activity implements TextWatcher {
private AutoCompleteTextView atv;
private TextView tv;
private ArrayAdapter<CharSequence> adapter; @Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub } @Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub } @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
tv.setText(atv.getText());
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
atv = (AutoCompleteTextView) findViewById(R.id.atv);
tv = (TextView) findViewById(R.id.textView1);
adapter = ArrayAdapter.createFromResource(this, R.array.test,
android.R.layout.simple_dropdown_item_1line);
atv.setAdapter(adapter);
atv.addTextChangedListener(this);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
android之AutoCompleteTextView控件用法的更多相关文章
- Android的Spinner控件用法解析
微调框 微调框提供一种方法,让用户可以从值集中快速选择一个值.默认状态下,微调框显示其当前所选的值. 触摸微调框可显示下拉菜单,其中列有所有其他可用值,用户可从中选择一个新值. 您可以使用 Spinn ...
- android之Spinner控件用法
用法1: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too ...
- android之RatingBar控件用法
MainActivity.java package com.example.mars_2500_ratingbar; import android.support.v7.app.ActionBarAc ...
- android之SeekBar控件用法
MainActivity.java package com.example.mars_2400_seekbar; import android.support.v7.app.ActionBarActi ...
- android之datepicker控件用法
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Android AutoCompleteTextView控件实现类似百度搜索提示,限制输入数字长度
Android AutoCompleteTextView 控件实现类似被搜索提示,效果如下 1.首先贴出布局代码 activity_main.xml: <?xml version="1 ...
- Android笔记---常用控件以及用法
这篇文章主要记录下Android的常用控件以及使用的方法,Android 给我们提供了大量的UI控件,合理地使用这些控件就可以非常轻松地编写出相当不错的界面,这些是Android学习的基础,没有什么业 ...
- Android 中常见控件的介绍和使用
1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...
- [Android] Android 卡片式控件CardView的优雅使用
[Android] Android 卡片式控件CardView的优雅使用 CardView是在安卓5.0提出的卡片式控件 其具体用法如下: 1.在app/build.gradle 文件中添加 comp ...
随机推荐
- c++特性:指向类成员的指针和非类型类模板参数和函数指针返回值 参数推导机制和关联型别
一.c++允许定义指向类成员的指针,包括类函数成员指针和类数据成员指针 格式如下: class A { public: void func(){printf("This is a funct ...
- Caffe-windows上训练自己的数据
1.数据获取 在网上选择特定类别,下载相应的若干张图片.可以网页另存或者图片下载器.本例中保存了小狗.菊花.梅花三类各两百多张. 2.重命名 import os import os.path root ...
- UserDefault的使用,保存小数据到本地-iOS
//保持到本地数据 NSArray *array=@[@"234",@"sdfe"]; NSUserDefaults *userDefault=[NSUserD ...
- CSS3盒模型之box-sizing
这些天在做一个手机端的页面,遇到了一些问题!首当其冲的就是盒子的溢出问题!大家都知道,手机的尺寸各异,各种型号的手机多得能闪瞎你们的眼睛,为了能 让这些设置更好的浏览我们的页面,我们已经不能固定页面的 ...
- linux 通用IO
open(),read(),write(),close()可以应用于管道,FIFO,socket,或者终端等所有文件类型执行IO操作. lseek()并不适用于所有类型的文件.不允许将lseek()应 ...
- OpenJudge计算概论-找最大数序列
/*===================================== 找最大数序列 总时间限制: 1000ms 内存限制: 65536kB 描述 输入n行(n 不大于 30),每行不超过10 ...
- python ImportError: No module named 的问题
https://my.oschina.net/leejun2005/blog/109679 python中,每个py文件被称之为模块,每个具有__init__.py文件的目录被称为包.只要模块或者包所 ...
- MySQL中Group By,distinct使用注意事项
mysql> select * from test; +----+-------+------+-------+ | id | name | age | class | +----+------ ...
- PIP安装Python的scipy,scrapy等包出现“failed building wheel for xxx”问题解决办法
1.在这里下载对应的.whl文件,注意别改文件名! http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Ctrl + F,输入lxml,找到下面这段 Lxm ...
- EV电池指标及特点
在电池的大家族中,蓄电池的种类是最多的,共同的特点是可以经历多次充电.放电循环,反复使用,这也正是蓄电池作为电动汽车动力源的基础.当然,并不是所有的蓄电池都适合应用于电动汽车,从全球新能源汽车的发展来 ...