android用户界面-组件Widget-常用组件
用户会员注册实例
介绍控件
文本框TextView
编辑框EditText
密码文本框EditText
单选按钮RadioButton
复选框CheckBox
开关按钮ToggleButton
下拉列表Spinner
实例:
注册页面
/Chapter04_UI_CommonWidget/src/com/amaker/test/MainActivity.java
- 代码
- package com.amaker.test;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.Spinner;
- import android.widget.ToggleButton;
- public class MainActivity extends Activity {
- private Button register,cancel;
- private ToggleButton marriged;
- private RadioButton male,female;
- private EditText username,password;
- private Spinner position;
- private CheckBox reading,swimming;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- username = (EditText)findViewById(R.id.username);
- password = (EditText)findViewById(R.id.password);
- male = (RadioButton)findViewById(R.id.male);
- female = (RadioButton)findViewById(R.id.female);
- reading = (CheckBox)findViewById(R.id.reading);
- swimming = (CheckBox)findViewById(R.id.swimming);
- marriged = (ToggleButton)findViewById(R.id.marriged);
- position = (Spinner)findViewById(R.id.position);
- String[] str = {"CEO","CFO","PM"};
- ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,str);
- position.setAdapter(aa);
- register = (Button)findViewById(R.id.register);
- cancel = (Button)findViewById(R.id.cancel);
- register.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- Bundle b = new Bundle();
- b.putString("username", "用户名称:"+username.getText().toString());
- b.putString("password", "用户密码:"+password.getText().toString());
- if(male.isChecked()){
- b.putString("gender", "性别:男");
- }else{
- b.putString("gender", "性别:女");
- }
- String temp = "爱好:";
- if(reading.isChecked()){
- temp+="阅读";
- }
- if(swimming.isChecked()){
- temp+=" ";
- temp+="游泳";
- }
- b.putString("hobby", temp);
- if(marriged.isChecked()){
- b.putString("marriged", "婚否:已婚");
- }else{
- b.putString("marriged", "婚否:未婚");
- }
- b.putString("position","职位:"+ position.getSelectedItem().toString());
- Intent intent = new Intent(MainActivity.this,ResultActivity.class);
- intent.putExtra("data", b);
- startActivity(intent);
- }
- });
- }
- }
注册结果页面
/Chapter04_UI_CommonWidget/src/com/amaker/test/ResultActivity.java
- 代码
- package com.amaker.test;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- public class ResultActivity extends Activity{
- private ListView listView;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.result);
- listView = (ListView) findViewById(R.id.ListView01);
- Intent intent = this.getIntent();
- Bundle b = intent.getBundleExtra("data");
- System.out.println(b.getString("username"));
- List list = new ArrayList();
- list.add(b.getString("username"));
- list.add(b.getString("password"));
- list.add(b.getString("position"));
- list.add(b.getString("gender"));
- list.add(b.getString("hobby"));
- list.add(b.getString("marriged"));
- ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,list);
- listView.setAdapter(adapter);
- }
- }
布局文件
/Chapter04_UI_CommonWidget/res/layout/main.xml
- 代码
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TableLayout
- android:id="@+id/TableLayout01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:stretchColumns="1"
- >
- <TableRow
- android:id="@+id/TableRow01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView
- android:text="用户名称"
- android:id="@+id/TextView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></TextView>
- <EditText
- android:text=""
- android:id="@+id/username"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- ></EditText>
- </TableRow>
- <TableRow
- android:id="@+id/TableRow02"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView
- android:text="用户密码"
- android:id="@+id/TextView02"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></TextView>
- <EditText
- android:text=""
- android:id="@+id/password"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:password="true"
- ></EditText>
- </TableRow>
- <TableRow
- android:id="@+id/TableRow03"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView
- android:text="性别"
- android:id="@+id/TextView03"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></TextView>
- <RadioGroup
- android:id="@+id/gender_g"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <RadioButton
- android:text="男"
- android:id="@+id/male"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></RadioButton>
- <RadioButton
- android:text="女"
- android:id="@+id/female"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></RadioButton>
- </RadioGroup>
- </TableRow>
- <TableRow
- android:id="@+id/TableRow04"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView
- android:text="婚否"
- android:id="@+id/TextView04"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></TextView>
- <ToggleButton
- android:text="@+id/ToggleButton01"
- android:id="@+id/marriged"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></ToggleButton>
- </TableRow>
- <TableRow
- android:id="@+id/TableRow05"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- >
- <TextView
- android:text="爱好"
- android:id="@+id/hobby"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></TextView>
- <CheckBox
- android:text="阅读"
- android:id="@+id/reading"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_column="1"
- ></CheckBox>
- <CheckBox
- android:text="游泳"
- android:id="@+id/swimming"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_column="1"
- ></CheckBox>
- </TableRow>
- <TableRow
- android:id="@+id/TableRow06"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView
- android:text="职务"
- android:id="@+id/TextView05"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></TextView>
- <Spinner
- android:id="@+id/position"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></Spinner>
- </TableRow>
- <TableRow
- android:id="@+id/TableRow07"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <Button
- android:text="取消"
- android:id="@+id/cancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></Button>
- <Button
- android:text="注册"
- android:id="@+id/register"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></Button>
- </TableRow>
- </TableLayout>
- </LinearLayout>
/Chapter04_UI_CommonWidget/res/layout/result.xml
- 代码
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <ListView
- android:id="@+id/ListView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"></ListView>
- </LinearLayout>
本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080698
android用户界面-组件Widget-常用组件相关推荐
- datastage中oracle组件,Datastage常用组件使用方法(详尽版)
常用组件使用方法: Sequential file1 功能特点:适用于一般顺序文件(定长或不定长),可识别文本文件或IBM大机ebcdic文件. 使用要点: 按照命名规范命名 点住文件,双击鼠标,在g ...
- android的33种常用组件1
view:view是android中所有ui组件的父类,他其实就是一个空白区域,然后所有的组件在继承这个view的基础上对他进行改造,将其捏成相应的形状,比如textview,button等等,所以说 ...
- java 图形用什么组件标题_java图形用户界面设计Swing常用组件(阅读).ppt
* * * * * Rows:列表框的行数 boolean multipleMode:指定列表框是否可以进行多项选择. 列表框:打开文件对话框中的文件类型. * * import javax.swin ...
- android java与界面的关联_Android Studio安卓学习笔记(三)Android用户界面的设计布局与组件(一)用户界面布局设计(1)...
当我们创建了一个安卓项目后,我们会发现真正建立一个完善的安卓项目并不是想象的那么容易.其实和设计GUI可视化界面一样,开发安卓也需要考虑很多方面,主要考虑的还是界面布局和需要的组件. 一:Androi ...
- Android常用组件收集
UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...
- Android常用组件类库
UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...
- Android常用组件(转来比较安全,万一作者删了就没了)
UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...
- Android Studio安卓学习笔记(三)Android用户界面的设计布局与组件(一)用户界面布局设计(1)...
当我们创建了一个安卓项目后,我们会发现真正建立一个完善的安卓项目并不是想象的那么容易.其实和设计GUI可视化界面一样,开发安卓也需要考虑很多方面,主要考虑的还是界面布局和需要的组件. 一:Androi ...
- Part3.Android基础知识 - 四大基本组件与常用控件完全解析
1.概要 1).Android四大基本组件 Activity Service Broadcast Receiver Content Provider 2).Android应用核心Intent Inte ...
- 图形用户界面常用组件
图形用户界面常用组件 1.按钮 JButton JButton anniu =new JButton("按钮"); 2.面板 JPanel JPanel mianban=new J ...
最新文章
- 关于学习Python的一点学习总结(28->收集参数及分配参数)
- oracle convertobject,oracle.sql進行轉換。TIMESTAMPLTZ@71d9d55b Java時間戳
- 系统诊断概述-如何通过windbg来dump特定process的memory.
- 浅谈计算机程序设计语言,探讨计算机程序设计语言教学
- 新东方在线战略亏损:扩张提速or高层动荡?
- Myeclipse学习总结(4)——Eclipse常用开发插件
- AI学会了视觉推理,“脑补”看不清的物体 | 李佳李飞飞等的CVPR论文
- 推荐《喵星人行为心理学》
- Python SQLite教程
- 连接SQL SERVER的时候登录名如何清除
- 前端Unicode字符图标汇总
- rost反剽窃检测系统_学术不端检测规则是什么?
- newifi路由器 php,[强如老狗]新路由3newifi3(newifi d2)修改eeprom解决2.4G信号问题修改MAC方法...
- 记录第一次用阿里云(Windows主机)部署SSM项目(Spring+SpringMVC+Mybatis)
- 数据库查询-分数排名
- Jmeter把响应数据结果保存到本地文件
- 用思维导图赏析老舍话剧著作《茶馆》
- vue玩转移动端H5微信支付和支付宝支付
- 选C++还是选Java,过来人给你一个建议
- 谷歌今遭遇史上至暗时刻,美司法部正式提起反垄断诉讼!22年前微软曾有此劫-1
热门文章
- linux windows文件 编码_Linux与Windows实现文件交互的几种方式
- 拼接名字_一个最简单的办法,教你识别原切肉和拼接肉
- vba查找数据并返回单元格地址_VBA积木代码中实现反向多值查找、LIKE模糊查找...
- pytorch 常见报错
- 【项目实战课】NLP入门第1课,人人免费可学,基于TextCNN的新闻文本分类实战...
- 中国钢铁行业战略规划及项目建设动态分析报告2021-2027年
- 中国楼宇自控系统发展规划现状及未来前景预测报告2022-2028年版
- 中国陶瓷辊棒市场全景调查及供需格局预测报告2022-2028年版
- 在Win7 64位注册ActiveX控件
- 中国农民丰收节交易会新闻发布会倡导功能农业·农业大健康