易网时代-编程资源站
Welcome
微信登录
首页
/
操作系统
/
Linux
/
Android组件RadioButton、checkBox、listview、spinner综合实例及Intent传值
组件解释:
RadioButton单选按钮
checkBox复选框
是一种有双状态按钮的特殊类型,可以选中或者不选中。
listview列表
列表的显示需要三个元素:
1.ListVeiw 用来展示列表的View。2.适配器 用来把数据映射到ListView上的中。3.数据 具体的将被映射的字符串,图片,或者基本组件。 根据列表的适配器类型,列表分为三种,
ArrayAdapter,
SimpleAdapter和SimpleCursorAdapter其中以ArrayAdapter最为简单,只能展示一行字。SimpleAdapter有最好的扩充性,可以自定义出各种效果。SimpleCursorAdapter可以认为是SimpleAdapter对数据库的简单结合,可以方面的把数据库的内容以列表的形式展示出来。
spiner下拉列表
(Spinner)是一个每次只能选择所有项中一项的部件。它的项来自于与之相关联的适配器中。Intent英文里 Intent是“意向、打算”的意思,其实就是告诉别人你的意图的意思了,这么理解Android里面的Intent也就不难了。
本文原码下载地址:
免费下载地址在
http://linux.linuxidc.com/
用户名与密码都是
www.linuxidc.com
具体下载目录在
/pub/Android源码集锦/2011年/12月/Android组件RadioButton、checkBox、listview、spinner综合实例及Intent传值/ 费话不多说,直接先看效果图:main.xml布局文件:
<?xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:orientation
=
"vertical"
>
<TextView
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:layout_gravity
=
"center"
android:gravity
=
"center"
android:text
=
"@string/hello"
android:textSize
=
"30dp"
android:textStyle
=
"bold"
/>
<TableLayout
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:stretchColumns
=
"1"
>
<TableRow
>
<TextView
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:layout_gravity
=
"center"
android:text
=
"用户名:"
/>
<EditText
android:id
=
"@+id/username"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:hint
=
"请输入用户名!!!"
/>
</TableRow>
<TableRow
>
<TextView
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:layout_gravity
=
"center"
android:text
=
"密码:"
/>
<EditText
android:id
=
"@+id/password"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:hint
=
"请输入密码!!!"
/>
</TableRow>
<TableRow
>
<TextView
android:layout_width
=
"wrap_content"
android:layout_height
=
"wrap_content"
android:layout_gravity
=
"center"
android:text
=
"性别:"
android:textSize
=
"20dp"
/>
<RadioGroup
android:id
=
"@+id/sex"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:checkedButton
=
"@+id/woman"
android:orientation
=
"horizontal"
>
<RadioButton
android:id
=
"@+id/nan"
android:text
=
"男"
/>
<RadioButton
android:id
=
"@id/woman"
android:text
=
"女"
/>
</RadioGroup>
</TableRow>
<TableRow
>
<TextView
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:layout_gravity
=
"center"
android:text
=
"爱好:"
android:textSize
=
"20dp"
/>
<TableLayout
android:id
=
"@+id/table"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:stretchColumns
=
"*"
>
<TableRow
>
<CheckBox
android:id
=
"@+id/cb1"
android:layout_width
=
"match_parent"
android:layout_height
=
"wrap_content"
android:text
=
"足球"
/>
<CheckBox
android:id
=
"@+id/cb2"
android:layout_width
=
"match_parent"
android:layout_height
=
"wrap_content"
android:text
=
"篮球"
/>
</TableRow>
<TableRow
>
<CheckBox
android:id
=
"@+id/cb3"
android:layout_width
=
"match_parent"
android:layout_height
=
"wrap_content"
android:text
=
"游戏"
/>
<CheckBox
android:id
=
"@+id/cb4"
android:layout_width
=
"match_parent"
android:layout_height
=
"wrap_content"
android:text
=
"游泳"
/>
</TableRow>
</TableLayout>
</TableRow>
<TableRow
>
<TextView
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"学历:"
/>
<Spinner
android:id
=
"@+id/sports"
android:layout_width
=
"match_parent"
android:layout_height
=
"wrap_content"
android:entries
=
"@array/educate"
android:prompt
=
"@string/educate"
/>
</TableRow>
</TableLayout>
<Button
android:layout_width
=
"100dp"
android:layout_height
=
"wrap_content"
android:layout_gravity
=
"center"
android:id
=
"@+id/button"
android:text
=
"注册"
/>
</LinearLayout>
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图