Question

I'm working on a custom ROM and I'm receiving this error while trying to compile it. I tried to add a custom battery selector.

com.android.settings.pcf.StatusBar is not abstract and does not override abstract method onPreferenceChange(android.preference.Preference,java.lang.Object) in android.preference.Preference.OnPreferenceChangeListener

This is the the com.android.settings.pcf.StatusBar file:

package com.android.settings.pcf;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.provider.Settings;

import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;

public class StatusBar extends SettingsPreferenceFragment implements OnPreferenceChangeListener {

    private static final String PREF_BATT_ICON = "battery_icon_list";

    ListPreference mBatteryIcon;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.prefs_statusbar);

        mBatteryIcon = (ListPreference) findPreference(PREF_BATT_ICON);
        mBatteryIcon.setOnPreferenceChangeListener(this);
        mBatteryIcon.setValue((Settings.System.getInt(getActivity()
                .getContentResolver(), Settings.System.STATUSBAR_BATTERY_ICON,
                0))
                + "");
    }

    public boolean OnPreferenceChange(Preference preference, Object newValue) {
        if (preference == mBatteryIcon) {
            int val = Integer.parseInt((String) newValue);
            return Settings.System.putInt(getActivity().getContentResolver(),
                    Settings.System.STATUSBAR_BATTERY_ICON, val);
        }
        return false;
    }
}

Can anyone help?

Was it helpful?

Solution

The error is telling you that you didn't fully implement the OnPreferenceChangeListener interface. In particular, the onPreferenceChange method is not implemented.

Either implement this method, or I'm actually guessing you meant OnPreferenceChange to be onPreferenceChange - note the lowercase "o" - (in which case I believe you will also need a @Override before it)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top