完成注册信息界面,部门列表框,单击确定检查提交成功、接受界面
开发环境: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"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别"/>
<RadioGroup
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/man"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="男"/>
<RadioButton
android:id="@+id/woman"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="女"/>
</RadioGroup>
<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>
<TextView
android:text="爱好"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="书籍"/>
<CheckBox
android:id="@+id/sport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="运动"/>
<CheckBox
android:id="@+id/music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="音乐"/>
<CheckBox
android:id="@+id/movie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电影"/>
</LinearLayout>
<Button
android:id="@+id/ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="确定"
android:onClick="myclick"/>
depts.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="dept">
<item>人力资源部</item>
<item>销售部</item>
<item>财务部</item>
<item>开发部</item>
</string-array>
</resources>
private ArrayList<CheckBox> 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>();
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:
<?xml version="1.0" encoding="utf-8"?>
<android.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">
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.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"));
手机扫一扫
移动阅读更方便
你可能感兴趣的文章