- 浏览: 80789 次
- 性别:
- 来自: 郑州
最新评论
-
老梦a:
...怎么用的呢,我把js和css都引入了,但是用的时候没起作 ...
在Ext的grid里实现带radio单选功能的gridList -
Mydwr:
我也正在找要实现这样的效果
在Ext的grid里实现带radio单选功能的gridList -
kkgoing:
运行不报错,但是还是有问题,index页面打不开,测试的时候插 ...
昨天整理的基于Annotation的MVC框架SSH示例 -
kjsoloho:
感谢你的肺腑之言
价值是如何放大的 -
kjsoloho:
希望继续,期待
《Android程序员指南》翻译暂停,望见谅
本节展示radiogroup.xml的全部代码。根据章节前面的指导创建一个新的名为radiogroup.xml的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"
>
<RadioGroup android:id="@+id/testRadioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioButton
android:text="Radio 1"
android:id="@+id/radio1"
/>
<RadioButton
android:text="Radio 2"
android:id="@+id/radio2" />
</RadioGroup>
<Button android:id="@+id/enableButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set isEnabled"/>
<Button android:id="@+id/backgroundColorButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Background Color"/>
</LinearLayout>
testRadioGroup.java
本节包含了实现RadioGroup Activity的最终文件。在项目中创建一个名为test RadioGroup.java的新.java文件。该文件时Activity的主文件并且包含了可执行的代码。在test RadioGroup.java中使用下面的代码来完善该Activity。
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.Button;
import android.graphics.Color;
public class testRadioGroup extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.radiogroup);
final RadioGroup radiogroup = (RadioGroup)
findViewById(R.id.testRadioGroup);
final Button changeButton = (Button)findViewById(R.id.enableButton);
changeButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
changeOption(radiogroup); }
});
final Button changeButton2 = (Button)
findViewById(R.id.backgroundColorButton);
changeButton2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
changeOption2(radiogroup);
}
});
}
public void changeOption(RadioGroup radiogroup){
if (radiogroup.isEnabled()){
radiogroup.setEnabled(false);
}
else{
radiogroup.setEnabled(true);
} }
public void changeOption2(RadioGroup radiogroup){
radiogroup.setBackgroundColor(Color.RED);
}
}
AndroidViews.java
创建这个Activity的最后一步是编辑AndroidViews.java。如果你想要从主AndroidViews Activity中调用testRadioGroup Activity,你必须给AndroidViews.java添加代码。比较一下下面的代码和你当前的AndroidViews.java。添加所需代码来完善你的文件。
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
public class AndroidViews extends Activity {
/** Called when the Activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, 0, "AutoComplete");
menu.add(0, 1, "Button");
menu.add(0, 2, "CheckBox");
menu.add(0, 3, "EditText");
menu.add(0, 4, "RadioGroup");
menu.add(0, 5, "Spinner");
return true;
}
@Override
public boolean onOptionsItemSelected(Menu.Item item){
switch (item.getId()) {
case 0:
showAutoComplete();
return true;
case 1:
showButton();
return true;
case 2:
showCheckBox();
return true;
case 3:
showEditText();
return true;
case 4:
showRadioGroup();
return true;
case 5:
showSpinner();
return true;
}
return true;
}
public void showButton() {
Intent showButton = new Intent(this, testButton.class);
startActivity(showButton);
}
public void showAutoComplete(){
Intent autocomplete = new Intent(this, AutoComplete.class);
startActivity(autocomplete);
}
public void showCheckBox(){
Intent checkbox = new Intent(this, testCheckBox.class);
startActivity(checkbox);
}
public void showEditText() {
Intent edittext = new Intent(this, testEditText.class);
startActivity(edittext);
}
public void showRadioGroup(){
Intent radiogroup = new Intent(this, testRadioGroup.class);
startActivity(radiogroup);
}
public void showSpinner(){
}
}
}
启动你的应用,并从菜单中选择Edittext选项。
下面的插图显示了RadioGroup Activity的样子。
双击Set isEnabled 和Change BackGroup Color按钮。结果就如下插图所示。注意RadioGroup的Set isEnabled按钮能禁用组,而Change BackGroup Color按钮能够改变组的背景色。
Spinner
在本节中,与上个类似,你会为Spinner 视图创建一个Activity。创建Spinner视图和其他编程语言中的ComboBox相似。创建Activity的步骤跟前面的章节中非常类似。因此会为你提供三个主要的Activity文件的全部代码——AndroidManifest.xml,spinner.xml和testSpinner.java。下面的会为你提供这些代码。
AndroidManifest.xml
本节包含了当前AndroidView的AndroidManifest.xml的全部代码。如果你在Eclipse中学习,将你的Activity的AndroidManifest.xml文件更改为如下这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="android_programmers_guide.AndroidViews">
<application android:icon="@drawable/icon">
<activity android:name=".AndroidViews"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AutoComplete" android:label="AutoComplete">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testButton" android:label="TestButton">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testCheckBox" android:label="TestCheckBox">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testEditText" android:label="TestEditText">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testRadioGroup" android:label="Test
RadioGroup">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".testSpinner" android:label="Test Spinner">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Spinner.xml
本节展示spinner.xml的全部代码。根据章节前面的指导创建一个新的名为spinner.xml的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"
>
<Spinner android:id="@+id/testSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/enableButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set isEnabled"/>
<Button android:id="@+id/backgroundColorButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Change Background Color"/>
</LinearLayout>
testSpinner.java
本节包含了实现Spinner Activity的最终文件。在项目中创建一个名为testSpinner.java的新.java文件。该文件时Activity的主文件并且包含了可执行的代码。在testSpinner.java中使用下面的代码来完善该Activity。
package android_programmers_guide.AndroidViews;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Button;
import android.graphics.Color;
simple_spinner_item, Months);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
final Button changeButton = (Button)findViewById(R.id.enableButton);
changeButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
changeOption(spinner); }
});
final Button changeButton2 = (Button)
findViewById(R.id.backgroundColorButton);
changeButton2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
changeOption2(spinner);
}
});
}
static final String[] Months = new String[]{
"January","February","March","April","May","June","July","August",
"September","October","November","December"
};
public void changeOption(Spinner spinner){
if (spinner.isEnabled()){
spinner.setEnabled(false);
}
else{
spinner.setEnabled(true);
}
}
public void changeOption2(Spinner spinner){
spinner.setBackgroundColor(Color.RED);
}
}
发表评论
-
第八章 列表、菜单以及其它视图——续
2010-03-19 09:00 1432AndroidViews.java 创建这个Activity ... -
第八章 列表、菜单以及其它视图——后
2010-03-19 08:50 1395AndroidViews.java 创建这个Activity ... -
第八章 列表、菜单以及其它视图——下
2010-03-19 08:42 1713这里是你的完整的AndroidManifest.xml项目文件 ... -
第八章 列表、菜单以及其它视图——中
2010-03-19 08:39 1628这段代码有个问题:onOptionsItemSelected( ... -
第八章 列表、菜单以及其它视图——上
2010-03-19 08:31 2562关键技能和概念 l 构建Activity l ... -
第七章 使用Intents与Phone Dialer——下
2010-03-02 09:23 1660实现EditText视图 你需要 ... -
第七章 使用Intents与Phone Dialer——中
2010-03-02 09:16 2609为给你的Activity分配正确的权限,你首先需要知道你需要分 ... -
第七章 使用Intents与Phone Dialer——上
2010-03-02 09:07 3764第一章 使用Intents与Phone Dialer ... -
第六章 使用命令行工具与Android模拟器——下
2010-02-25 16:49 6122由于你在Android服务端安放了应用,你就可以删除它。使用命 ... -
第六章 使用命令行工具与Android模拟器——中
2010-02-25 16:38 5340<arg value="install&quo ... -
第六章 使用命令行工具与Android模拟器——上
2010-02-25 16:25 4513关键技能和概念 l 使用Android SDK ... -
第五章 应用:Hello World!——下
2010-02-24 09:07 2605还是Hello World! 本节中,你会创建另一个 ... -
第五章 应用:Hello World!——上
2010-02-24 09:00 2327关键技能和概念 l ... -
第四章 探索Android SDK
2010-02-21 22:27 6163关键技能和概念 l ... -
第三章 下载、安装Android SDK
2010-02-20 16:19 6673关键技能和概念 l ... -
第二章 下载、安装Eclipse
2010-02-20 11:28 5322关键技能和概念 l 选择一个开发环境 l ... -
第一章 Android是什么?
2010-02-20 11:17 2042关键技能和概念 l 嵌入式编程的历史 l ... -
致谢与序言
2010-02-05 16:12 1288致谢 感谢所有参与编写这本书的人,我的经纪 ... -
为什么要翻译《Android A Programmer's Guide》——《Android程序员指南》
2010-02-05 16:08 2854学习Android编程,却发现这些方面的好书很少,于是 ...
相关推荐
第八章 本篇复习——控制台应用程序和长文件名 第二篇:字体和窗口控制 第九章 第八天课程——Windows 动画:Snake 游戏 第十章 第九天课程——字体基础知识 第十一章 第十天课程——窗口控制 第十二章 第十...
第8章:利用CDC实现绘图程序.ppt 第9章:Windows应用程序引擎——消息映射.ppt 第10章:用户交互对象——菜单、工具栏和状态栏.ppt 第11章:对话框及常用控件.ppt 第12章:基于文档/视图结构的程序.ppt 第13章:...
第8章Android应用程序组成 8.1深入理解Activity 8.1.1使用Intent连接Activity 8.1.2 Activity的生命周期 …… 第9章Android中的数据存储 第10章绚丽的多媒体技术 第11章Android网上冲浪 第12章Android地图服务 第4篇...
第8章Android应用程序组成 8.1深入理解Activity 8.1.1使用Intent连接Activity 8.1.2 Activity的生命周期 …… 第9章Android中的数据存储 第10章绚丽的多媒体技术 第11章Android网上冲浪 第12章Android地图服务 第4篇...
第8章 对话框和属性表 第Ⅱ部分 文档/视图体系结构 第9章 文档、视图和单文档界面 第10章 滚动视图、HTML视图以及其他视图类型 第11章 多文档和多视图 第12章 工具栏、状态栏和组合栏 第13章 打印和...
第8章 使用ActiveX控件 第9章 Internet Explorer 4通用控件 第10章 win32内存管理 第11章 位图 第12章 windows消息处理和多线程编程 第三部分 文档视图结构 第13章 菜单、键盘、加速键、多信息 第14章...
第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences存储 8.3 谁的文件,谁主宰——文件存储 8.4 打造自己的数据库存储——SQLite存储方式 8.4.1 Android...
第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences存储 8.3 谁的文件,谁主宰——文件存储 8.4 打造自己的数据库存储——SQLite存储方式 8.4.1 Android...
第8章 移动信息仓库——Android的数据存储操作 136 8.1 Android数据存储概述 136 8.2 轻轻地我保护——SharedPreferences存储 136 8.3 谁的文件,谁主宰——文件存储 140 8.4 打造自己的数据库存储——...
对话框高级应用 7.2.2 示例——实现无模式对话框 7.4.5 示例——使用模式属性表及向导属性表 7.5.4 示例——鼠标敏感文字 第8章 GDI+图形编程 本章示例通常含有多段被注释的演示代码,请读者查看...
对话框高级应用 7.2.2 示例——实现无模式对话框 7.4.5 示例——使用模式属性表及向导属性表 7.5.4 示例——鼠标敏感文字 第8章 GDI+图形编程 本章示例通常含有多段被注释的演示代码,请读者查看...
第8章 移动信息仓库——android的数据存储操作 136 8.1 android数据存储概述 136 8.2 轻轻地我保护——sharedpreferences存储 136 8.3 谁的文件,谁主宰——文件存储 140 8.4 打造自己的数据库存储——...
第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences存储 8.3 谁的文件,谁主宰——文件存储 8.4 打造自己的数据库存储——SQLite存储方式 8.4.1 Android...
计算机应用基础课件——Word排版知识全文共72页,当前为第8页。 3.3 文档基本操作 3.3.1 创建新文档 最常用的几种创建新文档的方式 3.3.2 打开文档 打开文档最快捷的方法就是在"资源管理 器"中双击需要的Word文档,...
第八章:Extjs组件结构 46 一、Extjs的组件结构远比我们想象的复杂 46 二、组件分类 47 三、组件的生命周期 48 四、组件渲染方法render 50 五、小结 52 第九章:按钮与日期选择器 53 一、开始组件学习之旅 53 二、被...
第8章 设计表格类布局 8.1 表格简介 8.1.1 表格的基本属性 8.1.2 制作第一个表格 8.2 表格常用功能详解 8.2.1 主要属性功能 8.2.2 自定义列宽度 8.2.3 执行按列排序 8.2.4 解决中文排序 8.2.5 格式化显示...