act_register.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:background="#f0f0f0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注 册"
android:textColor="#fff"
android:textSize="44sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="11dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名"
android:textSize="20sp" />
<EditText
android:id="@+id/reg_edit_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入用户名" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="11dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码"
android:textSize="20sp" />
<EditText
android:id="@+id/reg_edit_pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="11dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="重复密码"
android:textSize="20sp" />
<EditText
android:id="@+id/reg_edit_repwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请再次输入密码"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="11dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱"
android:textSize="20sp" />
<EditText
android:id="@+id/reg_edit_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入电子邮箱" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="11dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性 别"
android:textSize="20sp" />
<RadioGroup
android:id="@+id/reg_rg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/reg_rgman"
style="@android:style/Widget.Holo.CompoundButton.Star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="男" />
<RadioButton
android:id="@+id/reg_rgwoman"
style="@android:style/Widget.Holo.CompoundButton.Star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="女" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff" >
<Button
android:id="@+id/reg_but"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#6cf"
android:onClick="onRegClick"
android:text="提 交"
android:textColor="#fff"
android:textSize="22sp" />
</LinearLayout>
</LinearLayout>
act_usercenter.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:background="#f0f0f0"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册成功"
android:textColor="#fff"
android:textSize="44sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="12dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名"
android:textSize="20sp" />
<TextView
android:id="@+id/text_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#f00"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="12dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码"
android:textSize="20sp" />
<TextView
android:id="@+id/text_pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#f00"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="12dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱"
android:textSize="20sp" />
<TextView
android:id="@+id/text_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#f00"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#fff"
android:padding="12dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性 别"
android:textSize="20sp" />
<TextView
android:id="@+id/text_sex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#f00"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
RegisterActivity.java
package com.example.register;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class RegisterActivity extends Activity implements OnCheckedChangeListener{
private RadioGroup rg;
private RadioButton rgman,rgwoman;
private String checked_rg = "男";
private EditText ev_user,ev_pwd,ev_email;
private TextView user,pwd,email,sex;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.act_register);
initViews();
}
private void initViews() {
// TODO Auto-generated method stub
rg = (RadioGroup) findViewById(R.id.reg_rg);
rg.setOnCheckedChangeListener(this);
rgman = (RadioButton) findViewById(R.id.reg_rgman);
rgwoman = (RadioButton) findViewById(R.id.reg_rgwoman);
ev_user = (EditText) findViewById(R.id.reg_edit_user);
ev_pwd = (EditText) findViewById(R.id.reg_edit_pwd);
ev_email = (EditText) findViewById(R.id.reg_edit_email);
}
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
if(arg1 == R.id.reg_rgman)
checked_rg = "男";
else
checked_rg = "女";
}
public void onRegClick(View v){
switch(v.getId()){
case R.id.reg_but:
/*AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("恭喜!注册成功!信息如下:");
//一种提示信息,提示用户名、密码、邮箱等用户输入的信息
builder.setMessage("用户名:" + ev_user.getText().toString() +
"\n密码:" + ev_pwd.getText().toString() +
"\n邮箱:" + ev_email.getText().toString() +
"\n性别:" + checked_rg);
builder.setNegativeButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
});
builder.show();*/
//用Tost来做,Toast中显示一个新的Layout,并把用户输入的信息传过去
Toast toast = new Toast(this);
toast.setDuration(Toast.LENGTH_LONG);
LayoutInflater inflater = this.getLayoutInflater();
View view = inflater.inflate(R.layout.act_usercenter, null);
/*((TextView)findViewById(R.id.text_user)).setText(ev_user.getText().toString());
((TextView)findViewById(R.id.text_pwd)).setText(ev_pwd.getText().toString());
((TextView)findViewById(R.id.text_sex)).setText(checked_rg);
((TextView)findViewById(R.id.text_email)).setText(ev_email.getText().toString());*/
user = (TextView)view.findViewById(R.id.text_user);
pwd = (TextView) view.findViewById(R.id.text_pwd);
email = (TextView) view.findViewById(R.id.text_email);
sex = (TextView) view.findViewById(R.id.text_sex);
user.setText(ev_user.getText().toString());
pwd.setText(ev_pwd.getText().toString());
email.setText(ev_email.getText().toString());
sex.setText(checked_rg);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
//第三种方法:Dialog中显示一个新的Layout,并把用户输入的信息传过去
/*AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("fdsafds");
LayoutInflater inflater = this.getLayoutInflater();
View view = inflater.inflate(R.layout.act_usercenter, null);
builder.setView(view);
user = (TextView)view.findViewById(R.id.text_user);
pwd = (TextView) view.findViewById(R.id.text_pwd);
email = (TextView) view.findViewById(R.id.text_email);
sex = (TextView) view.findViewById(R.id.text_sex);
user.setText(ev_user.getText().toString());
pwd.setText(ev_pwd.getText().toString());
email.setText(ev_email.getText().toString());
sex.setText(checked_rg);
builder.show();*/
break;
}
}
}