你好,游客 登录 注册 搜索
背景:
阅读新闻

Android之路-EditText组件

[日期:2011-12-14] 来源:Linux社区  作者:xyf28190374 [字体:大 中 小]

模拟器显示效果:

et.setVisibility(View.INVISIBLE);

自动完成输入内容的组件

1、Activity文件

  1. package cn.class3g.activity;  
  2.   
  3. import Android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.widget.ArrayAdapter;  
  6. import android.widget.AutoCompleteTextView;  
  7. import android.widget.MultiAutoCompleteTextView;  
  8.   
  9. public class AutoCompleteActivity extends Activity {  
  10.   
  11.     AutoCompleteTextView autoTx = null;  
  12.     MultiAutoCompleteTextView mautoTx = null;  
  13.   
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.auto_complete);  
  17.         findViews();  
  18.   
  19.         String[] str = { "abc", "add", "axy", "aaaa", "bcd", "bbbd", "bdcc" };  
  20.   
  21.         ArrayAdapter adapter = new ArrayAdapter(this,  
  22.                 android.R.layout.simple_dropdown_item_1line, str);  
  23.   
  24.         autoTx.setAdapter(adapter);  
  25.           
  26.         //-------MulitAutoCompleteTextView   
  27.         mautoTx.setAdapter(adapter);  
  28.         mautoTx.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());  
  29.           
  30.     }  
  31.   
  32.     private void findViews() {  
  33.         autoTx = (AutoCompleteTextView) findViewById(R.id.autoTx);  
  34.         mautoTx = (MultiAutoCompleteTextView) findViewById(R.id.mautoTx);  
  35.     }  
  36.   
  37. }  

2、auto_complete.xml文件

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <AutoCompleteTextView   
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:id="@+id/autoTx"  
  11.         />  
  12.       
  13.     <MultiAutoCompleteTextView   
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="wrap_content"  
  16.         android:id="@+id/mautoTx"  
  17.         />  
  18.   
  19. </LinearLayout>  

模拟器显示效果:

当输入bb时,底部自动出现代码中存入的字符串 

注:如果在一个项目中创建了两个不同功能的Activity文件,在转换时应当对AdroidManifast.XML中的<intent-filter>做修改,将之移动到准备启动的<Activity>中,这点有时容易忽略,会造成模拟器错误。

linux
相关资讯       Android开发教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款