用户会员注册实例

介绍控件

文本框TextView

编辑框EditText

密码文本框EditText

单选按钮RadioButton

复选框CheckBox

开关按钮ToggleButton

下拉列表Spinner

实例:

注册页面

/Chapter04_UI_CommonWidget/src/com/amaker/test/MainActivity.java

  1. 代码
  2. package com.amaker.test;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.ArrayAdapter;
  9. import android.widget.Button;
  10. import android.widget.CheckBox;
  11. import android.widget.EditText;
  12. import android.widget.RadioButton;
  13. import android.widget.Spinner;
  14. import android.widget.ToggleButton;
  15. public class MainActivity extends Activity {
  16. private Button register,cancel;
  17. private ToggleButton marriged;
  18. private RadioButton male,female;
  19. private EditText username,password;
  20. private Spinner position;
  21. private CheckBox reading,swimming;
  22. @Override
  23. public void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.main);
  26. username = (EditText)findViewById(R.id.username);
  27. password = (EditText)findViewById(R.id.password);
  28. male = (RadioButton)findViewById(R.id.male);
  29. female = (RadioButton)findViewById(R.id.female);
  30. reading = (CheckBox)findViewById(R.id.reading);
  31. swimming = (CheckBox)findViewById(R.id.swimming);
  32. marriged = (ToggleButton)findViewById(R.id.marriged);
  33. position = (Spinner)findViewById(R.id.position);
  34. String[] str = {"CEO","CFO","PM"};
  35. ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,str);
  36. position.setAdapter(aa);
  37. register = (Button)findViewById(R.id.register);
  38. cancel = (Button)findViewById(R.id.cancel);
  39. register.setOnClickListener(new OnClickListener() {
  40. public void onClick(View v) {
  41. Bundle b = new Bundle();
  42. b.putString("username", "用户名称:"+username.getText().toString());
  43. b.putString("password", "用户密码:"+password.getText().toString());
  44. if(male.isChecked()){
  45. b.putString("gender", "性别:男");
  46. }else{
  47. b.putString("gender", "性别:女");
  48. }
  49. String temp = "爱好:";
  50. if(reading.isChecked()){
  51. temp+="阅读";
  52. }
  53. if(swimming.isChecked()){
  54. temp+=" ";
  55. temp+="游泳";
  56. }
  57. b.putString("hobby", temp);
  58. if(marriged.isChecked()){
  59. b.putString("marriged", "婚否:已婚");
  60. }else{
  61. b.putString("marriged", "婚否:未婚");
  62. }
  63. b.putString("position","职位:"+ position.getSelectedItem().toString());
  64. Intent intent = new Intent(MainActivity.this,ResultActivity.class);
  65. intent.putExtra("data", b);
  66. startActivity(intent);
  67. }
  68. });
  69. }
  70. }

注册结果页面

/Chapter04_UI_CommonWidget/src/com/amaker/test/ResultActivity.java

  1. 代码
  2. package com.amaker.test;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import android.app.Activity;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.widget.ArrayAdapter;
  9. import android.widget.ListView;
  10. public class ResultActivity extends Activity{
  11. private ListView listView;
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.result);
  15. listView = (ListView) findViewById(R.id.ListView01);
  16. Intent intent = this.getIntent();
  17. Bundle b = intent.getBundleExtra("data");
  18. System.out.println(b.getString("username"));
  19. List list =  new ArrayList();
  20. list.add(b.getString("username"));
  21. list.add(b.getString("password"));
  22. list.add(b.getString("position"));
  23. list.add(b.getString("gender"));
  24. list.add(b.getString("hobby"));
  25. list.add(b.getString("marriged"));
  26. ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,list);
  27. listView.setAdapter(adapter);
  28. }
  29. }

布局文件

/Chapter04_UI_CommonWidget/res/layout/main.xml

  1. 代码
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. >
  8. <TableLayout
  9. android:id="@+id/TableLayout01"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:stretchColumns="1"
  13. >
  14. <TableRow
  15. android:id="@+id/TableRow01"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content">
  18. <TextView
  19. android:text="用户名称"
  20. android:id="@+id/TextView01"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"></TextView>
  23. <EditText
  24. android:text=""
  25. android:id="@+id/username"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. ></EditText>
  29. </TableRow>
  30. <TableRow
  31. android:id="@+id/TableRow02"
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content">
  34. <TextView
  35. android:text="用户密码"
  36. android:id="@+id/TextView02"
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"></TextView>
  39. <EditText
  40. android:text=""
  41. android:id="@+id/password"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:password="true"
  45. ></EditText>
  46. </TableRow>
  47. <TableRow
  48. android:id="@+id/TableRow03"
  49. android:layout_width="wrap_content"
  50. android:layout_height="wrap_content">
  51. <TextView
  52. android:text="性别"
  53. android:id="@+id/TextView03"
  54. android:layout_width="wrap_content"
  55. android:layout_height="wrap_content"></TextView>
  56. <RadioGroup
  57. android:id="@+id/gender_g"
  58. android:layout_width="wrap_content"
  59. android:layout_height="wrap_content">
  60. <RadioButton
  61. android:text="男"
  62. android:id="@+id/male"
  63. android:layout_width="wrap_content"
  64. android:layout_height="wrap_content"></RadioButton>
  65. <RadioButton
  66. android:text="女"
  67. android:id="@+id/female"
  68. android:layout_width="wrap_content"
  69. android:layout_height="wrap_content"></RadioButton>
  70. </RadioGroup>
  71. </TableRow>
  72. <TableRow
  73. android:id="@+id/TableRow04"
  74. android:layout_width="wrap_content"
  75. android:layout_height="wrap_content">
  76. <TextView
  77. android:text="婚否"
  78. android:id="@+id/TextView04"
  79. android:layout_width="wrap_content"
  80. android:layout_height="wrap_content"></TextView>
  81. <ToggleButton
  82. android:text="@+id/ToggleButton01"
  83. android:id="@+id/marriged"
  84. android:layout_width="wrap_content"
  85. android:layout_height="wrap_content"></ToggleButton>
  86. </TableRow>
  87. <TableRow
  88. android:id="@+id/TableRow05"
  89. android:layout_width="wrap_content"
  90. android:layout_height="wrap_content"
  91. >
  92. <TextView
  93. android:text="爱好"
  94. android:id="@+id/hobby"
  95. android:layout_width="wrap_content"
  96. android:layout_height="wrap_content"></TextView>
  97. <CheckBox
  98. android:text="阅读"
  99. android:id="@+id/reading"
  100. android:layout_width="wrap_content"
  101. android:layout_height="wrap_content"
  102. android:layout_column="1"
  103. ></CheckBox>
  104. <CheckBox
  105. android:text="游泳"
  106. android:id="@+id/swimming"
  107. android:layout_width="wrap_content"
  108. android:layout_height="wrap_content"
  109. android:layout_column="1"
  110. ></CheckBox>
  111. </TableRow>
  112. <TableRow
  113. android:id="@+id/TableRow06"
  114. android:layout_width="wrap_content"
  115. android:layout_height="wrap_content">
  116. <TextView
  117. android:text="职务"
  118. android:id="@+id/TextView05"
  119. android:layout_width="wrap_content"
  120. android:layout_height="wrap_content"></TextView>
  121. <Spinner
  122. android:id="@+id/position"
  123. android:layout_width="wrap_content"
  124. android:layout_height="wrap_content"></Spinner>
  125. </TableRow>
  126. <TableRow
  127. android:id="@+id/TableRow07"
  128. android:layout_width="wrap_content"
  129. android:layout_height="wrap_content">
  130. <Button
  131. android:text="取消"
  132. android:id="@+id/cancel"
  133. android:layout_width="wrap_content"
  134. android:layout_height="wrap_content"></Button>
  135. <Button
  136. android:text="注册"
  137. android:id="@+id/register"
  138. android:layout_width="wrap_content"
  139. android:layout_height="wrap_content"></Button>
  140. </TableRow>
  141. </TableLayout>
  142. </LinearLayout>

/Chapter04_UI_CommonWidget/res/layout/result.xml

  1. 代码
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="fill_parent"
  7. >
  8. <ListView
  9. android:id="@+id/ListView01"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"></ListView>
  12. </LinearLayout>

本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080698

android用户界面-组件Widget-常用组件相关推荐

  1. datastage中oracle组件,Datastage常用组件使用方法(详尽版)

    常用组件使用方法: Sequential file1 功能特点:适用于一般顺序文件(定长或不定长),可识别文本文件或IBM大机ebcdic文件. 使用要点: 按照命名规范命名 点住文件,双击鼠标,在g ...

  2. android的33种常用组件1

    view:view是android中所有ui组件的父类,他其实就是一个空白区域,然后所有的组件在继承这个view的基础上对他进行改造,将其捏成相应的形状,比如textview,button等等,所以说 ...

  3. java 图形用什么组件标题_java图形用户界面设计Swing常用组件(阅读).ppt

    * * * * * Rows:列表框的行数 boolean multipleMode:指定列表框是否可以进行多项选择. 列表框:打开文件对话框中的文件类型. * * import javax.swin ...

  4. android java与界面的关联_Android Studio安卓学习笔记(三)Android用户界面的设计布局与组件(一)用户界面布局设计(1)...

    当我们创建了一个安卓项目后,我们会发现真正建立一个完善的安卓项目并不是想象的那么容易.其实和设计GUI可视化界面一样,开发安卓也需要考虑很多方面,主要考虑的还是界面布局和需要的组件. 一:Androi ...

  5. Android常用组件收集

    UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...

  6. Android常用组件类库

    UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...

  7. Android常用组件(转来比较安全,万一作者删了就没了)

    UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...

  8. Android Studio安卓学习笔记(三)Android用户界面的设计布局与组件(一)用户界面布局设计(1)...

    当我们创建了一个安卓项目后,我们会发现真正建立一个完善的安卓项目并不是想象的那么容易.其实和设计GUI可视化界面一样,开发安卓也需要考虑很多方面,主要考虑的还是界面布局和需要的组件. 一:Androi ...

  9. Part3.Android基础知识 - 四大基本组件与常用控件完全解析

    1.概要 1).Android四大基本组件 Activity Service Broadcast Receiver Content Provider 2).Android应用核心Intent Inte ...

  10. 图形用户界面常用组件

    图形用户界面常用组件 1.按钮 JButton JButton anniu =new JButton("按钮"); 2.面板 JPanel JPanel mianban=new J ...

最新文章

  1. 关于学习Python的一点学习总结(28->收集参数及分配参数)
  2. oracle convertobject,oracle.sql進行轉換。TIMESTAMPLTZ@71d9d55b Java時間戳
  3. 系统诊断概述-如何通过windbg来dump特定process的memory.
  4. 浅谈计算机程序设计语言,探讨计算机程序设计语言教学
  5. 新东方在线战略亏损:扩张提速or高层动荡?
  6. Myeclipse学习总结(4)——Eclipse常用开发插件
  7. AI学会了视觉推理,“脑补”看不清的物体 | 李佳李飞飞等的CVPR论文
  8. 推荐《喵星人行为心理学》
  9. Python SQLite教程
  10. 连接SQL SERVER的时候登录名如何清除
  11. 前端Unicode字符图标汇总
  12. rost反剽窃检测系统_学术不端检测规则是什么?
  13. newifi路由器 php,[强如老狗]新路由3newifi3(newifi d2)修改eeprom解决2.4G信号问题修改MAC方法...
  14. 记录第一次用阿里云(Windows主机)部署SSM项目(Spring+SpringMVC+Mybatis)
  15. 数据库查询-分数排名
  16. Jmeter把响应数据结果保存到本地文件
  17. 用思维导图赏析老舍话剧著作《茶馆》
  18. vue玩转移动端H5微信支付和支付宝支付
  19. 选C++还是选Java,过来人给你一个建议
  20. 谷歌今遭遇史上至暗时刻,美司法部正式提起反垄断诉讼!22年前微软曾有此劫-1

热门文章

  1. linux windows文件 编码_Linux与Windows实现文件交互的几种方式
  2. 拼接名字_一个最简单的办法,教你识别原切肉和拼接肉
  3. vba查找数据并返回单元格地址_VBA积木代码中实现反向多值查找、LIKE模糊查找...
  4. pytorch 常见报错
  5. 【项目实战课】NLP入门第1课,人人免费可学,基于TextCNN的新闻文本分类实战...
  6. 中国钢铁行业战略规划及项目建设动态分析报告2021-2027年
  7. 中国楼宇自控系统发展规划现状及未来前景预测报告2022-2028年版
  8. 中国陶瓷辊棒市场全景调查及供需格局预测报告2022-2028年版
  9. 在Win7 64位注册ActiveX控件
  10. 中国农民丰收节交易会新闻发布会倡导功能农业·农业大健康