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

Android软件开发之EditText 详解

[日期:2011-08-12] 来源:Linux社区  作者:雨松MOMO [字体:大 中 小]

EditText在API中的结构

java.lang.Object

 Android.view.View

  android.widget.TextView       

   android.widget.EditText

已知直接子类:

   AutoCompleteTextView, ExtractEditText

已知间接子类:

   MultiAutoCompleteTextView

EditText是TextView的直接子类 所以EditText会继承父类TextView的一些方法。下面我用自己写的一个Demo 和大家详细的说明一下EditView的使用方法。

1.简单的EditText输入框

非常简单,在layout布局中配置一下EditText 在配置一个Button 在代码中监听Button 的事件 获取当前EditView中输入的内容并且显示出来。

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/textviewll"  
  4.     android:orientation="vertical" android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent">  
  6.     <EditText    
  7.       android:id="@+id/sample_edit_text0"      
  8.       android:layout_width="fill_parent"     
  9.       android:layout_height="wrap_content"   
  10.       android:text="简单的EditText输入框"/>   
  11.     <Button   
  12.       android:id="@+id/sample_button0"  
  13.       android:layout_width="fill_parent" android:layout_height="wrap_content"  
  14.       android:text="确定"/>  
  15. </LinearLayout>  
  1. public class SampleActivity extends Activity {  
  2.     @Override  
  3.     protected void onCreate(Bundle savedInstanceState) {  
  4.     setContentView(R.layout.sample);  
  5.       
  6.     final EditText editText0 = (EditText)findViewById(R.id.sample_edit_text0);  
  7.   
  8.     Button button0 = (Button)findViewById(R.id.sample_button0);  
  9.   
  10.     button0.setOnClickListener(new OnClickListener() {  
  11.           
  12.         @Override  
  13.         public void onClick(View arg0) {  
  14.         String str = editText0.getText().toString();  
  15.         Toast.makeText(SampleActivity.this,str, Toast.LENGTH_LONG).show();  
  16.         }  
  17.     });  
  18.   
  19.     super.onCreate(savedInstanceState);  
  20.     }  
  21. }  
linux
相关资讯       Android教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

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