初步用户注册页面

来源:互联网 发布:淘宝客软件下载 编辑:程序博客网 时间:2024/06/09 23:03
注册页面千变万化,但基本信息也就那么几项。这里只是对于常用的一些信息注册做了小小的编译,可以在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;@Overridepublic 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();}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}
划线的地方还可以经过修改,进行信息的完善显示
对于里面的信息通过填写,选择进行确定:
点击“确定”就能成功注册,显示注册成功的对话框。
弹出注册成功的对话框可以通过添加showactivity文件完成,这里就不多说了。
经过和老师的效果图对比发现日期的格式不一样:
这只是日期格式的问题,选择时选择中文格式的就可以。
原创粉丝点击