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.易做图_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.易做图_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="选择您的性别"
&nbs
补充:移动开发 , Android ,