<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="姓名"
android:textSize="30dp"
/>
<EditText android:id="@+id/e1"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="性别"
android:textSize="30dp"
/>
<RadioGroup android:id="@+id/rg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:text="男"
android:textSize="30dp"/>
<RadioButton android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:text="女"
android:textSize="30dp"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView android:id="@+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="专业"
android:textSize="30dp"
/>
<TextView android:id="@+id/t4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="计算机科学与技术"
android:textSize="30dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView android:id="@+id/t5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="兴趣爱好"
android:textSize="30dp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<CheckBox android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="音乐"
android:textSize="20dp"
android:layout_marginLeft="20dp"/>
<CheckBox android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="运动"
android:textSize="20dp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<CheckBox android:id="@+id/cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="游泳"
android:textSize="20dp"
android:layout_marginLeft="20dp"/>
<CheckBox android:id="@+id/cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="阅读"
android:textSize="20dp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<Button android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提交"
android:layout_marginLeft="20dp"/>
<Button android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="取消"
android:layout_marginLeft="10dp"/>
</LinearLayout>
</LinearLayout>
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.RadioButton
import android.widget.TextView
import android.widget.Toast
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
final TextView textView=(TextView)findViewById(R.id.t1)
TextView textView1=(TextView)findViewById(R.id.t2)
TextView textView2=(TextView)findViewById(R.id.t3)
final TextView textView3=(TextView)findViewById(R.id.t4)
TextView textView4=(TextView)findViewById(R.id.t5)
final EditText editText=(EditText)findViewById(R.id.e1)
final RadioButton radioButton=(RadioButton)findViewById(R.id.rb1)
final RadioButton radioButton1=(RadioButton)findViewById(R.id.rb2)
final CheckBox checkBox=(CheckBox)findViewById(R.id.cb1)
final CheckBox checkBox1=(CheckBox)findViewById(R.id.cb2)
final CheckBox checkBox2=(CheckBox)findViewById(R.id.cb3)
final CheckBox checkBox3=(CheckBox)findViewById(R.id.cb4)
Button button=(Button)findViewById(R.id.b1)
Button button1=(Button)findViewById(R.id.b2)
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(editText.length()==0)
Toast.makeText(getApplicationContext(), "请输入你的姓名",
Toast.LENGTH_SHORT).show()
else
{
String str=null
str+="你好"+editText.getText()+"\n"
str+="你的性别是:"
if(radioButton.isChecked())
str+=radioButton.getText()
else
str+=radioButton1.getText()
str+="!\n你的专业是"+textView3.getText()+"!\n你的个人爱好有:"
if(checkBox.isChecked())
str+=checkBox.getText()
if(checkBox1.isChecked())
str+=","+checkBox1.getText()
if(checkBox2.isChecked())
str+=","+checkBox2.getText()
if(checkBox3.isChecked())
str+=","+checkBox3.getText()
str+='!'
Toast.makeText(getApplicationContext(), str,
Toast.LENGTH_SHORT).show()
}
}
})
}
}