1. 程式人生 > 實用技巧 >Activity使用者註冊介面

Activity使用者註冊介面

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tv1"
        android:layout_width
="wrap_content" android:layout_height="wrap_content" android:text="使用者名稱:" android:textSize="30dp" android:layout_marginTop="30dp" android:textColor="#FFA500" /> <EditText android:layout_width="600dp" android:layout_height="wrap_content" android:id
="@+id/et1" android:layout_toRightOf="@id/tv1" android:layout_marginTop="20dp" android:textSize="30dp" /> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密 碼:" android:textSize
="30dp" android:layout_marginTop="50dp" android:layout_below="@+id/tv1" android:textColor="#FFA500" /> <EditText android:id="@+id/et2" android:layout_width="600dp" android:layout_height="wrap_content" android:layout_toRightOf="@+id/tv2" android:layout_marginTop="30dp" android:textSize="30dp" android:layout_below="@+id/et1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性別:" android:layout_marginLeft="1dp" android:layout_below="@id/tv2" android:layout_marginTop="20dp" android:textSize="40dp" android:textColor="#FF0000"/> <RadioGroup android:id="@+id/rb" android:layout_width="197dp" android:layout_height="wrap_content" android:layout_below="@id/tv2" android:layout_centerHorizontal="true" android:layout_marginTop="10dp"> <RadioButton android:id="@+id/rb1" android:layout_width="97dp" android:layout_height="79dp" android:text="男" android:textSize="30dp"/> <RadioButton android:id="@+id/rb2" android:layout_width="97dp" android:layout_height="79dp" android:text="女" android:textSize="30dp" /> </RadioGroup> <TextView android:id="@+id/tv3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="愛好:" android:layout_below="@id/rb" android:textSize="40dp" android:layout_marginLeft="1dp" android:textColor="#FF0000"/> <CheckBox android:layout_width="100dp" android:layout_height="60dp" android:id="@+id/cb1" android:layout_toRightOf="@id/tv3" android:layout_below="@id/rb" android:text="籃球" android:textSize="30dp" /> <CheckBox android:layout_width="100dp" android:layout_height="60dp" android:id="@+id/cb2" android:layout_toRightOf="@id/cb1" android:layout_below="@id/rb" android:text="足球" android:textSize="30dp" /> <CheckBox android:layout_width="100dp" android:layout_height="60dp" android:id="@+id/cb3" android:layout_toRightOf="@id/cb2" android:layout_below="@id/rb" android:text="排球" android:textSize="30dp" /> <Button android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@id/cb1" android:layout_centerHorizontal="true" android:text="註冊" android:textSize="45dp" android:onClick="click" android:layout_marginTop="10dp" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TheSecond">

   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/tv1"
       android:text="你的註冊資訊是:"
       android:textSize="30dp"
       android:layout_centerHorizontal="true"
       android:layout_marginTop="20dp"
       android:layout_marginBottom="50dp"
       />
    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="使用者名稱:"
        android:textSize="20dp"
        android:layout_below="@id/tv1"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et1"
        android:layout_marginTop="4dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/tv1"
        />
    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密    碼:"
        android:textSize="20dp"
        android:layout_below="@id/tv2"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et2"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/et1"
        />
    <TextView
        android:id="@+id/tv4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="性    別:"
        android:textSize="20dp"
        android:layout_below="@id/tv3"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et3"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/et2"
        />
    <TextView
        android:id="@+id/tv5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="愛    好:"
        android:textSize="20dp"
        android:layout_below="@id/tv4"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et4"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/et3"
        />


</RelativeLayout>
package com.example.register;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void click(View v){
        String name =((EditText)findViewById(R.id.et1)).getText().toString();
        String password =((EditText)findViewById(R.id.et2)).getText().toString();
        Intent it1=new Intent(this,TheSecond.class);
        it1.putExtra("name",name);
        it1.putExtra("password",password);
        final RadioGroup size =(RadioGroup)findViewById(R.id.rb);
        int selected=size.getCheckedRadioButtonId();

        switch (selected){
            case R.id.rb1:
                it1.putExtra("boy","男");
                break;
            case R.id.rb2:
                it1.putExtra("girl","女");
                break;
        }
        CheckBox c1=(CheckBox)findViewById(R.id.cb1);
        CheckBox c2=(CheckBox)findViewById(R.id.cb2);
        CheckBox c3=(CheckBox)findViewById(R.id.cb3);
        if(c1.isChecked()){
            it1.putExtra("bask","籃球");
        }
        if(c2.isChecked()){
            it1.putExtra("foot","足球");
        }
        if(c3.isChecked()){
            it1.putExtra("volley","排球");
        }
        startActivity(it1);
    }


}