24小时热门版块排行榜    

查看: 420  |  回复: 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 的主题更新
信息提示
请填处理意见