Regist
来源:互联网 发布:北京盛世光明软件 编辑:程序博客网 时间:2024/05/17 05:13
主要代码:
activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" ><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" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" tools:context=".MainActivity" /> <EditText android:id="@+id/edittext1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView1" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/edittext1" android:text="@string/sex" tools:context=".MainActivity" /> <RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="男" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="女" /> </RadioGroup> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/birthday" tools:context=".MainActivity" /> <DatePicker android:id="@+id/datePicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hobby" tools:context=".MainActivity" /> <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="看电影" /> <CheckBox android:id="@+id/checkBox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打篮球" /> <CheckBox android:id="@+id/checkBox3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="逛街" /> <CheckBox android:id="@+id/checkBox4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打羽毛球" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="提交" /> </LinearLayout></LinearLayout></ScrollView>
MainActivity.java
package com.example.register;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.DatePicker;import android.widget.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;public class MainActivity extends Activity {private EditText editText1;private RadioButton radioButton1;private RadioButton radioButton2;private RadioGroup radioGroup;private DatePicker datePicker;private CheckBox checkBox1;private CheckBox checkBox2;private CheckBox checkBox3;private CheckBox checkBox4;private Button button;String sex;String hobby;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 初始化组件editText1 = (EditText) this.findViewById(R.id.edittext1);radioButton1 = (RadioButton) this.findViewById(R.id.radioButton1);radioButton2 = (RadioButton) this.findViewById(R.id.radioButton2);radioGroup = (RadioGroup) this.findViewById(R.id.radioGroup);datePicker = (DatePicker) this.findViewById(R.id.datePicker1);checkBox1 = (CheckBox) this.findViewById(R.id.checkBox1);checkBox2 = (CheckBox) this.findViewById(R.id.checkBox2);checkBox3 = (CheckBox) this.findViewById(R.id.checkBox3);checkBox4 = (CheckBox) this.findViewById(R.id.checkBox4);button = (Button) this.findViewById(R.id.button1);// 注册事件监听器radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {if (R.id.radioButton1 == checkedId)sex = "男";if (R.id.radioButton2 == checkedId)sex = "女";}});button.setOnClickListener(new ButtonHandler());}// 定义事件处理类private class ButtonHandler implements OnClickListener {@Overridepublic void onClick(View v) {AlertDialog.Builder registDialog = new AlertDialog.Builder(MainActivity.this);String editString = editText1.getText().toString();String date = datePicker.getYear() + "年" + datePicker.getMonth()+ "月" + datePicker.getDayOfMonth() + "日";if (checkBox1.isChecked()) {hobby = hobby + "," + checkBox1.getText();}if (checkBox2.isChecked()) {hobby = hobby + "," + checkBox2.getText();}if (checkBox3.isChecked()) {hobby = hobby + "," + checkBox3.getText();}if (checkBox4.isChecked()) {hobby = hobby + "," + checkBox4.getText();}Toast.makeText(MainActivity.this,"注册成功!\n您的姓名:" + editString + "\n您的性别是:" + sex + "\n您的生日是:"+ date + "\n您的爱好:" + hobby, Toast.LENGTH_LONG).show();}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}
strings.xml
<resources> <string name="app_name">Register</string> <string name="hello_world">请输入您的姓名:</string> <string name="sex">请输入您的性别:</string> <string name="birthday">请输入您的生日:</string> <string name="hobby">请输入您的兴趣爱好:</string> <string name="menu_settings">Settings</string> <string name="title_activity_main">MainActivity</string></resources>
主要运行图:
- Regist
- Regist a form in EBS
- django错误 -- TypeError at /regist/
- regist too many Broadcast问题研究
- js的regist()和form的action
- 异常 java.security.AccessControlException: access denied (javax.management.MBeanTrustPermission regist
- C语言中,auto、regist、static、const、volatile
- C语言中,auto、regist、static、const、volatile
- <s:form action="user!regist" method="post">
- volatile到底有什么用?和regist有什么区别?
- Cannot implicitly convert type 'System.Collections.ArrayList' to 'object[]' ;System.Security.SecurityException: Requested regist
- There is no Action mapped for action name mylogin!regist错误原因
- LINUX KERNEL 配置编译中文指南
- Busybox支持中文的解决办法
- EFSL文件系统移植记录
- Android Game Development - Displaying Images with Android
- Red Hat linux进入单用户环境
- Regist
- 计算机技术课实验报告(1)
- 计算机技术课实验报告(2)
- android触摸语音事件
- GigE Vision攝像機接口標准
- Camera Link接口標准
- 一个计算机爱好者的不完整回忆(四十四)算是误入歧途
- 计算机技术课实验报告(3)
- 310. No man is content. 人心不足蛇吞象