初步用戶註冊頁面

註冊頁面千變萬化,但基本信息也就那麼幾項。這裏只是對於常用的一些信息註冊做了小小的編譯,可以在android上運行哦!

首先,填寫一下自己的基本信息,如圖:

一 佈局:

layout中的activity_main.xml中:

<LinearLayout 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"
    android:background="@drawable/bg"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/nameinput1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nameinput1"
        tools:context=".MainActivity" />

    <EditText
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />

    <TextView
        android:id="@+id/nameinput2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nameinput2"
        tools:context=".MainActivity" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radioButton1" />

    <RadioButton
        android:id="@+id/radioButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radioButton2" />

    <TextView
        android:id="@+id/nameinput3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nameinput3"
        tools:context=".MainActivity" />

    <DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="14dp" />

    <TextView
        android:id="@+id/nameinput4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nameinput4"
        tools:context=".MainActivity" />

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkBox1" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkBox2" />

    <Button
        android:id="@+id/click"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/clickbutton" />

</LinearLayout>

佈局的同時還需對裏面出現的變量進行定義:

strings.xml

<resources>

    <string name="app_name">用戶註冊頁面</string>
    <string name="nameinput1">請輸入你的姓名:</string>
    <string name="nameinput2">請輸入你的性別:</string>
    <string name="radioButton1">男</string>
    <string name="radioButton2">女</string>
    <string name="nameinput3">請輸入你的生日:</string>
    <string name="nameinput4">請輸入你的興趣愛好:</string>
    <string name="checkBox1">唱歌</string>
    <string name="checkBox2">看電影</string>
    <string name="clickbutton">提交</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">用戶註冊頁面</string>
    <string name="title_activity_show">ShowActivity</string>

</resources>

最重要的要數實現功能的activity了,好比“佈局是面子,方法是裏子。”只有佈局沒方法,是運行不起來的。現在就看我的了:

package w3.dyp.document;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class MainActivity extends Activity {

	private EditText nameInput1;
	private EditText nameInput2;
	private EditText nameInput3;
	private EditText nameInput4;

	public EditText getNameInput1() {
		return nameInput1;
	}

	public EditText getNameInput2() {
		return nameInput2;
	}

	public EditText getNameInput3() {
		return nameInput3;
	}

	public EditText getNameInput4() {
		return nameInput4;
	}

	private RadioButton radioButton1;
	private RadioButton radioButton2;
	private Button clickbutton;
	private CheckBox checkBox1;
	private CheckBox checkBox2;

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

		nameInput1 = (EditText) this.findViewById(R.id.name);
		clickbutton = (Button) this.findViewById(R.id.click);

		clickbutton.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				String name = nameInput1.getText().toString();
				Toast.makeText(MainActivity.this, "你好" + name+"你已經成功註冊",
						Toast.LENGTH_LONG).show();
			}

		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
}
劃線的地方還可以經過修改,進行信息的完善顯示
對於裏面的信息通過填寫,選擇進行確定:
點擊“確定”就能成功註冊,顯示註冊成功的對話框。
彈出註冊成功的對話框可以通過添加showactivity文件完成,這裏就不多說了。
經過和老師的效果圖對比發現日期的格式不一樣:
這只是日期格式的問題,選擇時選擇中文格式的就可以。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章