将控制权传递给Preference活动的问题

时间:2010-11-03 05:27:39

标签: android

我创建了应用程序,它将根据菜单选项从主活动调用首选项 它是使用Explicit intent完成的,但它不起作用。单击菜单项时 呼叫活动

public boolean onCreateOptionsMenu(Menu menu)
{
    super.onCreateOptionsMenu(menu);

    menu.add(0,  Menu.FIRST+1, Menu.NONE, "Refresh");
    menu.add(0, Menu.FIRST+3, Menu.NONE, "Set Preferences");

    return true;
}

public boolean onOptionItemSelected(MenuItem item)
{
    switch(item.getItemId()) 
    {
        case Menu.FIRST+1:
            Intent intent =new Intent(this,userpreferences.class);
            startActivityForResult(intent,this.USER_PREFERENCES);
            return true;

        case Menu.FIRST+3:

            return true;    
    }

    return false;
}

偏好xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <CheckBoxPreference
        android:key="AUTO_UPDATE" android:title="update automatically"
        android:summary="update automatically" android:defaultValue="true" />
    <ListPreference android:key="MINIMUM_MARK" android:title="minimum mark"     
        android:summary="enter the minimum mark of the student" 
        android:defaultValue="30" android:entries = "@array/minimumMarks"   
        android:entryValues="@array/minimum_mark_values" 
        android:dialogTitle="Check the minimum mark required" />
</PreferenceScreen>

偏好活动

package com.xml.parse;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class userpreferences extends PreferenceActivity
{
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }
}
有些人告诉我要做得更好或更正确

此致

Kariyachan

1 个答案:

答案 0 :(得分:1)

不要使用startActivityForResult() - startActivity()没问题。 Here is a sample project显示使用选项菜单项打开PreferenceActivity