安卓开发-个人名片制作

  1. MainActivity.java
package com.example.day4_exercise;


import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
private EditText edittext1,edittext2,edittext3,edittext4,edittext5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edittext1);
        edittext1=(EditText)findViewById(R.id.edittext1);
        edittext2=(EditText)findViewById(R.id.edittext2);
        edittext3=(EditText)findViewById(R.id.edittext3);
        edittext4=(EditText)findViewById(R.id.edittext4);
        edittext5=(EditText)findViewById(R.id.edittext5);

    }

    public void btnregister(View view){

        if(edittext1.length()<4){

            Toast.makeText(MainActivity.this, "姓名至少4位", Toast.LENGTH_LONG).show();
            return;
        }

        if(edittext2.length()<6){

            Toast.makeText(MainActivity.this, "密码至少6位", Toast.LENGTH_LONG).show();
            return;
        }

         if(edittext2.getText().toString() .equals(edittext3.getText().toString())==false){

            Toast.makeText(MainActivity.this, "重复密码必须与密码一致", Toast.LENGTH_LONG).show();
            return;
        }
         if(edittext4.length() != 11){

                Toast.makeText(MainActivity.this, "电话号码长度必须是11位", Toast.LENGTH_LONG).show();
                return;
            }
         if(edittext5.getText().toString().contains("@")==false){

                Toast.makeText(MainActivity.this, "邮箱地址格式错误", Toast.LENGTH_LONG).show();
                return;
            }


        Toast.makeText(MainActivity.this, "注册成功", Toast.LENGTH_LONG).show();
    }
public void btncancel(View view){
        edittext1.setText("");
        edittext2.setText("");
        edittext3.setText("");
        edittext4.setText("");
        edittext5.setText("");
        return;

    }

}
  1. edittext1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:weightSum="7">
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"

        android:orientation="horizontal"
        android:weightSum="4"
        >
        <TextView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="姓名"
            android:textSize="20sp"
            android:gravity="center"
            />
        <EditText 
           android:id="@+id/edittext1" 
           android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:inputType="text"

            />
    </LinearLayout>

       <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"

        android:orientation="horizontal"
        android:weightSum="4"
        >
        <TextView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="密码"
            android:textSize="20sp"
            android:gravity="center"
            />
        <EditText 
            android:id="@+id/edittext2" 
           android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:inputType="textPassword"

            />
    </LinearLayout>
       <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"

        android:orientation="horizontal"
        android:weightSum="4"
        >
        <TextView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="重复密码"
            android:textSize="20sp"
            android:gravity="center"
            />
        <EditText 
            android:id="@+id/edittext3" 
           android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:inputType="textPassword"

            />
    </LinearLayout>
       <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"

        android:orientation="horizontal"
        android:weightSum="4"
        >
        <TextView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="电话"
            android:textSize="20sp"
            android:gravity="center"
            />
        <EditText 
            android:id="@+id/edittext4" 
           android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:inputType="number"

            />
    </LinearLayout>
       <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"

        android:orientation="horizontal"
        android:weightSum="4"
        >
        <TextView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="邮箱"
            android:textSize="20sp"
            android:gravity="center"
            />
        <EditText 
            android:id="@+id/edittext5" 
           android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
           android:inputType="textEmailAddress"
            />
    </LinearLayout>
     <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="horizontal"
        android:weightSum="2"
         >
        <RelativeLayout 
         android:layout_width="0dp"
        android:layout_height="match_parent"
       android:layout_weight="1"
           >
           <Button 
               android:id="@+id/button1"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="取消"
               android:layout_centerInParent="true"
               android:onClick="btncancel"
               />

       </RelativeLayout>
       <RelativeLayout 
         android:layout_width="0dp"
        android:layout_height="match_parent"
       android:layout_weight="1"
           >
           <Button 
               android:id="@+id/button2"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="注册"
               android:layout_centerInParent="true"
               android:onClick="btnregister"
               />

           <TextView 
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="2017/12/10制作"
               android:layout_below="@id/button2"
               android:layout_alignLeft="@id/button2"
               />
       </RelativeLayout>

       </LinearLayout>


</LinearLayout>

这里写图片描述

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

仙剑老祖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值