我有一个包含三个片段类的活动。尝试从其中更改操作栏标题时出现错误。如果我尝试将这些类设为 public 而不是 public static,则在尝试启动该类时会出现错误。应该很清楚,代码是针对偏好的,尽管这不会改变任何东西。这是代码:
package com.simon.wikiics;
import android.preference.*;
import android.os.*;
import java.util.*;
public class MainSettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.headers, target);
}
//If I don't make the classes static my app force closes when I try to start them
public static class NavigationSettingsActivity extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.navigation);
//The getActionBar() is what is giving me the error
getActionBar().setTitle("Navigation");
}
}
public static class InterfaceSettingsActivity extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.interf);
//The getActionBar() is what is giving me the error
getActionBar().setTitle("Interface");
}
}
public static class OtherSettingsActivity extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.other);
//The getActionBar() is what is giving me the error
getActionBar().setTitle("Other");
}
}
}