安卓关于EditText的简单用法及intent传输ArrayList

安卓关于EditText的简单用法及intent传输ArrayList

EditText的简单用法

EditText,文本编辑框,在现实生活中使用很多很多,比如登入页面的账号密码输入框,打电话时输入电话号码,发邮件写的邮箱,而Android Studio又仔细对这些进行细分(很实用),比如一般的文字编辑框,使用Plain Text,一些可见数字用Number,一些不可见数字字符集合用Password,需求不同,显示方式也不同,放张图,就不一一说了。
在这里插入图片描述

实例

这里来一个实例,写一个学生的姓名,年龄,性别并显示出来,使用LinearLayout布局,三个编辑框都一样,直接复制粘贴改一下就行了,为了节省空间我这里就放一个,xml代码如下。

<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="@string/name"
        android:text="" />
<TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" />

values下的strings添加:

<string name="name">姓名</string>

ems属性表示的是编辑框的长度占几个字符。

inputType表示编辑框类型。

hint属性是在用户还没有输入的时候进行的半透明提示

这是XML的效果图:

在这里插入图片描述

活动

接下来写活动,要达到用户写完提交以后显示出来。

先将EditText、Button、textView作为私有的全局变量,方便后面的使用,用findViewById()通过id号找到对应的控件,都是一样的方法,写完一个直接copy成下一个

public class MainActivity extends Activity {
   
private Button button1;
    private  Button button2;
    private Button button3;
    EditText editText1;
    EditText editText2;
    EditText editText3;
    TextView textView1;
    TextView textView2;
    TextView textView3;
     @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button1=findViewById(R.id.button1);
        button2=findViewById(R.id.button2);
       
        editText1=findViewById(R.id.editText1);
        editText2=findViewById(R.id.editText2);
        editText3=findViewById(R.id.editText3);

        textView1=findViewById(R.id.textView1);
        textView2=findViewById(R.id.textView2);
        textView3=findViewById(R.id.textView3);
         button1.setOnClickListener(new View.OnClickListener() {
   
            @Overrid
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值