工程代码下载地址
完成注册信息界面,部门列表框,单击确定检查提交成功、接受界面
开发环境:Android Studio
模拟运行:Android Emulator – Nexus_5X_API_24
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名!"
/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
"wrap_content"
android:layout_height="wrap_content"
android:text="性别"/>
id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
id="@+id/man"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="男"/>
id="@+id/woman"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="女"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="联系电话"/>
<EditText
android:id="@+id/tel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|phone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="部门"/>
<Spinner
android:id="@+id/dept"
android:entries="@array/dept"
android:layout_width="wrap_content"
android:layout_height="wrap_content">Spinner>
text="爱好"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
"wrap_content"
android:layout_height="wrap_content">
id="@+id/book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="书籍"/>
id="@+id/sport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="运动"/>
id="@+id/music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="音乐"/>
id="@+id/movie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电影"/>
depts.xml:
<resources>
<string-array name="dept">
<item>人力资源部item>
<item>销售部item>
<item>财务部item>
<item>开发部item>
string-array>
resources>
private ArrayList favs;
private EditText userName;
private EditText password;
private EditText telephone;
private Spinner dept;
private RadioGroup sex;
private RadioButton man;
private RadioButton woman;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userName=(EditText)findViewById(R.id.name);
password=(EditText)findViewById(R.id.password);
telephone=(EditText)findViewById(R.id.tel);
sex=(RadioGroup)findViewById(R.id.sex);
dept=(Spinner)findViewById(R.id.dept);
man=(RadioButton)findViewById(R.id.man);
woman=(RadioButton)findViewById(R.id.woman);
favs=new ArrayList();
CheckBox book=(CheckBox) findViewById(R.id.book);
CheckBox sport=(CheckBox) findViewById(R.id.sport);
CheckBox music=(CheckBox) findViewById(R.id.music);
CheckBox movie=(CheckBox) findViewById(R.id.movie);
favs.add(book);
favs.add(sport);
favs.add(music);
favs.add(movie);
}
public String getSex(){
RadioButtonradioButton= (RadioButton)findViewById(sex.getCheckedRadioButtonId());
return radioButton.getText().toString();
}
public String getFavorite()
{
String favo="";
for(CheckBox cb:favs){
if(cb.isChecked()){
favo+=cb.getText().toString();
favo+=",";
}
}
if(!"".equals(favo))
favo=favo.substring(0,favo.length()-1);
else
favo="您未选择爱好!";
return favo;
}
public void myclick(View view){
//if (true){
StringBuilder sb =new StringBuilder();
sb.append("用户名: "+userName.getText().toString()+"\n");
Log.v("name","done");
sb.append("性别: "+getSex()+"\n");
Log.v("sex","done");
sb.append("电话: "+telephone.getText().toString()+"\n");
Log.v("tel","done");
sb.append("部门: "+dept.getSelectedItem().toString()+"\n");
Log.v("part","done");
sb.append("爱好: "+getFavorite()+"\n");
Log.v("fav","done");
Toast.makeText(this,sb.toString(),Toast.LENGTH_LONG).show();
Intent intent = new Intent();
intent.setClass(this,ResultActivity.class);
intent.putExtra("info",sb.toString());
this.startActivity(intent);
//}
}
result_activity.xml:
"1.0" encoding="utf-8"?>
.support.constraint.ConstraintLayout 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="com.example.zkj.test2.ResultActivity">
"@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent" />
.support.constraint.ConstraintLayout>
ResultActivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_result);
TextView result =(TextView)findViewById(R.id.result);
result.setText("从前一页面传来如下:\n\n"+this.getIntent().getStringExtra("info"));