24小时热门版块排行榜    

查看: 447  |  回复: 2

张小贩123

银虫 (小有名气)

[求助] 懂得进来看看 金币可以再商量么 哈哈

3,PreferenceActivityTest:

package com.example.activity01;

import java.util.List;

import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.app.Activity;
import android.app.ExpandableListActivity;
import android.app.LauncherActivity;
import android.content.Intent;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PreferenceActivityTest extends PreferenceActivity {
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(hasHeaders()){
         Button button=new Button(this);
         button.setText("设置操作";
         setListFooter(button);
        }
        
   
    }

@Override
public void onBuildHeaders(List<Header> target) {
  // TODO Auto-generated method stub
  loadHeadersFromResource(R.xml.preference_headers,target);
}
    public static class Prefs1Fragment extends PreferenceFragment{

  @Override
  public void onCreate(Bundle savedInstanceState) {
   // TODO Auto-generated method stub
   super.onCreate(savedInstanceState);
   addPreferencesFromResource(R.xml.preferences);
  }
     
    }
    public static class Prefs2Fragment extends PreferenceFragment{

  @Override
  public void onCreate(Bundle savedInstanceState) {
   // TODO Auto-generated method stub
   super.onCreate(savedInstanceState);
   addPreferencesFromResource(R.xml.display_prefs);
  }
      
  }
     
}
除此之外,在res.xml下面 还有三个布局文件:

1,preference_headers,xml:

<?xml version="1.0" encoding="utf-8"?>
<Preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
    <header android:fragment="com.example.activity01.PreferenceActivityTest$Prefs1Fragment"
        android:icon="@drawable/ic_settings_applications"
        android:title="程序选项设置"
        android:summary="设置应用的相关选项"
    />
    <header android:fragment="com.example.activity01.PreferenceActivityTest$Prefs2Fragment"
        android:icon="@drawable/ic_settings_display"
        android:title="界面选项设置"
        android:summary="设置显示界面的相关选项">
   </header>
</Preference-headers>
2.display_prefs.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <PreferenceCategory android:title="背景灯光组">
        <ListPreference android:key="light"
                        android:title="灯光强度"
                        android:summary="请选择灯光强度"
                        android:dialogTitle="请选择灯光强度"
/>
    </PreferenceCategory>
    <PreferenceCategory android:title="文字显示组">
        <SwitchPreference android:key="autoScroll"
            android:title="自动滚屏"
            android:summaryOn="自动滚屏:开启"
            android:summaryOff="自动滚屏:关闭"
            android:defaultValue="true"/>
    </PreferenceCategory>
</PreferenceScreen>
3,preferences.xml:

<?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:key="ring_key"
       android:showSilent="true"
/>
    <PreferenceCategory android:title="个人信息组">
        <EditTextPreference
            android:key="name"
            android:title="填写用户名"
            android:summary="填写您的用户名"
            android:dialogTitle="您所使用的用户名为:"/>
        <ListPreference android:key="gender"
                        android:title="性别"
                        android:summary="选择您的性别"
                        android:dialogTitle="ListPreference"/>
    </PreferenceCategory>
    <PreferenceCategory android:title="系统功能设置组">
        <CheckBoxPreference android:key="autoSave"
            android:title="自动保存进度"
            android:summaryOn="自动保存:开启"
            android:summaryOff="自动保存:关闭"
            android:defaultValue="true"/>
    </PreferenceCategory >
   

</PreferenceScreen>


我的这个程序编译没有报错,但是安装运行之后如果点击主界面的“设置程序参数”选项,就会死机,不知道为什么,希望各位高手指教!!!
回复此楼

» 猜你喜欢

独立
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

张新群

木虫 (正式写手)

【答案】应助回帖

膜拜,哥,你赢了!!!看不懂有木有!!

[ 发自手机版 http://muchong.com/3g ]
2楼2014-05-01 08:39:30
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

gxytju2008

专家顾问 (文坛精英)

【答案】应助回帖

貌似这边很少有码农来的吧。。去专业论坛问问比较靠谱
3楼2014-05-02 13:29:42
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 张小贩123 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 求调剂,一志愿:南京航空航天大学大学 ,080500材料科学与工程学硕,总分289分 +5 @taotao 2026-03-19 5/250 2026-03-24 21:07 by greychen00
[考研] 289求调剂 +8 硕星赴 2026-03-23 8/400 2026-03-24 20:17 by peike
[考研] 085602 289分求调剂 +5 WWW西西弗斯 2026-03-24 5/250 2026-03-24 18:51 by jhhcooi
[考研] 274求调剂 +5 顾九笙要谦虚 2026-03-24 5/250 2026-03-24 18:43 by jhhcooi
[考研] 300求调剂,材料科学英一数二 +5 leaflight 2026-03-24 5/250 2026-03-24 16:25 by laoshidan
[考研] 307求调剂 +5 超级伊昂大王 2026-03-24 5/250 2026-03-24 15:46 by 星空星月
[材料工程] 一志愿C9材料与化工专业总分300求调剂 +4 曼111 2026-03-24 5/250 2026-03-24 15:44 by 星空星月
[考研] 一志愿北京化工大学 070300 学硕 336分 求调剂 +7 vv迷 2026-03-22 7/350 2026-03-23 23:44 by Txy@872106
[考研] 361求调剂 +3 Glack 2026-03-22 3/150 2026-03-23 22:03 by fuyu_
[考研] 333求调剂 +6 87639 2026-03-21 10/500 2026-03-23 10:41 by Iveryant
[考研] 一志愿北京化工大学070300 学硕336求调剂 +5 vv迷 2026-03-21 8/400 2026-03-22 14:20 by ColorlessPI
[考研] 材料学硕301分求调剂 +7 Liyouyumairs 2026-03-21 7/350 2026-03-21 22:31 by peike
[考研] 求调剂 +3 13341 2026-03-20 3/150 2026-03-21 18:28 by 学员8dgXkO
[考研] 材料 271求调剂 +5 展信悦_ 2026-03-21 5/250 2026-03-21 17:29 by 学员8dgXkO
[考研] 279求调剂 +5 红衣隐官 2026-03-21 5/250 2026-03-21 14:59 by lature00
[考研] 22 350 本科985求调剂,求老登收留 +3 李轶男003 2026-03-20 3/150 2026-03-21 13:28 by 搏击518
[考研] 330求调剂0854 +3 assdll 2026-03-21 3/150 2026-03-21 13:01 by 搏击518
[考研] 求调剂 +6 Mqqqqqq 2026-03-19 6/300 2026-03-21 08:04 by JourneyLucky
[考研] 求调剂一志愿南京航空航天大学289分 +3 @taotao 2026-03-19 3/150 2026-03-20 21:34 by JourneyLucky
[考研] 材料考研调剂 +3 xwt。 2026-03-19 3/150 2026-03-19 11:22 by w沐阳w
信息提示
请填处理意见