Android开发学习之LauncherActivity开发启动的列表
-
Android开发学习之LauncherActivity开发启动的列表
创建项目:OtherActivity
项目运行结果:


建立主Activity:OtherActivity.java
[java]
package wwj.otherActivity;
import android.os.Bundle;
import android.app.Activity;
import android.app.LauncherActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.support.v4.app.NavUtils;
public class OtherActivity extends LauncherActivity {
//定义两个Activity的名称
String[] names = {"设置程序参数", "查看星际兵种"};
//定义两个Activity对应的实现类
Class<?>[] clazzs = {PreferenceActivityTest.class,
ExpandableListActivityTest.class};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1
, names);
// 设置该窗口显示的列表所需的Adapter
setListAdapter(adapter);
}
//根据列表项返回指定Activity对应的Intent
@Override
protected Intent intentForPosition(int position) {
// TODO Auto-generated method stub
return new Intent(OtherActivity.this, clazzs[position]);
}
}package wwj.otherActivity;
import android.os.Bundle;
import android.app.Activity;
import android.app.LauncherActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.support.v4.app.NavUtils;public class OtherActivity extends LauncherActivity {
//定义两个Activity的名称
String[] names = {"设置程序参数", "查看星际兵种"};
//定义两个Activity对应的实现类
Class<?>[] clazzs = {PreferenceActivityTest.class,
ExpandableListActivityTest.class};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1
, names);
// 设置该窗口显示的列表所需的Adapter
setListAdapter(adapter);
}
//根据列表项返回指定Activity对应的Intent
@Override
protected Intent intentForPosition(int position) {
// TODO Auto-generated method stub
return new Intent(OtherActivity.this, clazzs[position]);
}
}
建立第一个列表项的Activity:PreferenceActivityTest.java[java]
package wwj.otherActivity;
import android.os.Bundle;
public class PreferenceActivityTest extends android.preference.PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//设置显示参数设置布局
addPreferencesFromResource(R.xml.preferences);
}
}package wwj.otherActivity;
import android.os.Bundle;
public class PreferenceActivityTest extends android.preference.PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//设置显示参数设置布局
addPreferencesFromResource(R.xml.preferences);
}
}PreferenceActivity使用的界面布局文件
[html]
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置系统铃声 -->
<RingtonePreference
android:ringtoneType="all"
android:title="设置铃声"
android:summary="选择铃声"
android:showDefault="true"
android:key="ring_key"
android:showSilent="true">
</RingtonePreference>
<PreferenceCategory
android:title="个人信息设置组">
<!-- 通过输入框填写用户名 -->
<EditTextPreference
android:key="name"
android:title="用户名"
android:summary="填写你的用户名"
android:dialogTitle="您所使用的用户名为: "
/>
<!-- 通过列表框选择性别 -->
<ListPreference
android:key="gender"
android:title="性别"
android:summary="选择您的性别"
android:dialogTitle="ListPreference"
android:entries="@array/gender_name_list"
android:entryValues="@array/gender_value_list"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="系统功能设置组">
<CheckBoxPreference
android:key="autoSave"
android:title="自动保存进度"
android:summaryOn="自动保存 :开启"
android:summaryOff="自动保存:关闭"
android:defaultValue="true"/>
</PreferenceCategory>
</PreferenceScreen><?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置系统铃声 -->
<RingtonePreference
android:ringtoneType="all"
android:title="设置铃声"
android:summary="选择铃声"
android:showDefault="true"
android:key="ring_key"
android:showSilent="true">
</RingtonePreference>
<PreferenceCategory
android:title="个人信息设置组">
<!-- 通过输入框填写用户名 -->
<EditTextPreference
android:key="name"
android:title="用户名"
android:summary="填写你的用户名"
android:dialogTitle="您所使用的用户名为: "
/>
<!-- 通过列表框选择性别 -->
<ListPreference
android:key="gender"
android:title="性别"
android:summary="选择您的性别"
android:dialogTitle="ListPreference"
android:entries="@array/gender_name_list"
android:entryValues="@array/gender_value_list"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="系统功能设置组">
<CheckBoxPreference
android:key="autoSave"
android:title="自动保存进度"
android:summaryOn="自动保存 :开启"
android:summaryOff="自动保存:关闭"
android:defaultValue="true"/>
</PreferenceCategory>
</PreferenceScreen>
数组文件:array.xml[html]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="gender_name_list">
<item>男</item>
<item>女</item>
</string-array>
<string-array name="gender_value_list">
<item>male</item>
<item>female</item>
</string-array>
</resources><?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="gender_name_list">
<item>男</item>
<item>女</item>
</string-array>
<string-array name="gender_value_list">
<item>male</item>
<item>female</item>
</string-array>
</resources>创建第二个列表项的Activity:ExpandableListActivity.java
[java]
package wwj.otherActivity;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ExpandableListActivityTest extends ExpandableListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
int[] logos = new int[]{
R.drawable.p,
R.drawable.z,
R.drawable.t
};
private String[] armTypes = new String[]
{"神族兵种", "虫族兵种", "人族兵种"};
private String[][] arms = new String[][]{
{"狂战士", "龙骑士", "黑暗圣堂", "点兵"},
{"小狗", "刺蛇", "飞龙", "自爆飞机" },
{"机枪兵", "护士MM", "幽灵"}
};
//获取指定组位置、指定子列表项处的子列表项数据
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return arms[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;};
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return arms[groupPosition].length;
}
private TextView getTextView(){
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(ExpandableListActivityTest.this);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
textView.setPadding(36, 0, 0, 0);
textView.setTextSize(20);
return textView;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView textView = getTextView();
textView.setText(getChild(groupPosition, childPosition).toString());
return textView;
}
//获取指定位置处的组数据
public Object getGroup(int groupPosition) {
return armTypes[groupPosition];
};
public int getGroupCount() {
// TODO Auto-generated method stub
return armTypes.length;
}
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LinearLayout ll = new LinearLayout(ExpandableListActivityTest.this);
ll.setOrientation(0);
ImageView logo = new ImageView(ExpandableListActivityTest.this);
logo.setImageResource(logos[groupPosition]);
ll.addView(logo);
TextView textView = getTextView();
textView.setText(getGroup(groupPosition).toString());
ll.addView(textView);
return ll;
}
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
public boolean isChildSelectable(int groupPosition,
int childPosition) {
// TODO Auto-generated method stub
return true;
}
};
//设置该窗口显示列表
setListAdapter(adapter);
}
}
Android开发学习之LauncherActivity开发启动的列表的更多相关文章
- Android:日常学习笔记(8)———开发微信聊天界面
Android:日常学习笔记(8)———开发微信聊天界面 只做Nine-Patch图片 Nine-Patch是一种被特殊处理过的PNG图片,能够指定哪些区域可以被拉升,哪些区域不可以.
- android开发学习---linux下开发环境的搭建&& android基础知识介绍
一.配置所需开发环境 1.基本环境配置 JDK 5或以上版本(仅有JRE不够) (http://www.oracle.com/technetwork/java/javase/downloads/ind ...
- Android再学习-便签开发小结-20141119
这几天的便签开发,首先遇到的问题就是数据库操作问题.现在已经可以读写数据库了,并能将数据放在正确的位置显示. 专门建立了一个数据库操作的包,命名为"...database".新建一 ...
- <WP8开发学习笔记>动态修改启动时导航的第一个页面(如登录前启动页为LoginPage,登录后变为MainPage)
很多时候我们需要在启动程序的时候根据状态改变初始导航页面,比如程序在启动的时候判断用户是否登录, 如果未登录则跳转到LoginPage.xaml否则跳转到MainPage界面. 这时候就要分析程序的启 ...
- Android Activity学习笔记——Activity的启动和创建
http://www.cnblogs.com/bastard/archive/2012/04/07/2436262.html 最近学习Android相关知识,感觉仅仅了解Activity几个生命周期函 ...
- JavaWeb开发学习(一)-JavaWeb开发概述
1.Web相关概念 Web程序也就是一般所说的网站,由服务器.客户端浏览器以及网络组成.Web程序的好处是使用简单,不需要安装.学习,有一台电脑.一根网线就可以使用.Web程序不是一般意义上的网站.网 ...
- python开发学习-day02(元组、字符串、列表、字典深入)
s12-20160109-day02 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- 吴裕雄--天生自然 R语言开发学习:集成开发环境\工具RStudio的安装与配置
- 吴裕雄--天生自然 JAVA开发学习:Java 开发环境配置
随机推荐
- 安装pip之后,执行pip,提示:unknown or unsupported command install
安装pip之后,在dos命令框中输入pip,提示:unknown or unsupported command install,搜索之后,立马在:http://stackoverflow.com/qu ...
- 如何使用Github仓库创建网站
官方文档:https://help.github.com/categories/github-pages-basics/ 1.创建一个仓库 2.额外建立一个gh-pages分支 3.添加CNAME文件 ...
- CTSC && APIO 总结
先说CTSC吧,第一试其实不难但是下意识觉得CTSC不就只能骗分吗,然后就全上暴力了.然而第二题再一次看漏了条件,即答案总和小于等于1e6.第三题现在回想起来要不然就是没有思考,要不然就是没学过数学, ...
- 深入浅出Z-Stack 2006 OSAL多任务资源分配机制
转自深入浅出Z-Stack 2006 OSAL多任务资源分配机制 一.概述 OSAL (Operating System Abstraction Layer),翻译为"操作系统抽象层&quo ...
- 远程仓库版本回退方法 good
1 简介 最近在使用git时遇到了远程分支需要版本回滚的情况,于是做了一下研究,写下这篇博客. 2 问题 如果提交了一个错误的版本,怎么回退版本? 如果提交了一个错误的版本到远程分支,怎么回退远程分支 ...
- Default Web Site
win7上设置默认website的物理路径
- [C# 网络编程系列]专题五:TCP编程
转自:http://www.cnblogs.com/zhili/archive/2012/08/25/2656840.html 前言 前面专题的例子都是基于应用层上的HTTP协议的介绍, 现在本专题来 ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- MVC批量导出数据方法
近段时间做了个数据平台,其中涉及到批量导出CSV格式数据的业务,主要使用了部分视图和视图之间传值等知识点,今天做了下整理,特此分享下: 主要分为四步: 1:要打印的数据格式陈列View: 2:自定义导 ...
- HDU-1716 排列2 (DFS)
排列2 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...