@Override注释错误(安卓preFS) [英] @Override annotation error (android prefs)

查看:126
本文介绍了@Override注释错误(安卓preFS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图用这个code,使preferences到我的应用程序

When I was trying to use this code to enable preferences into my app

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;


public class Preferences extends PreferenceActivity {

private RadioButton btn01;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    btn01 = (RadioButton)findViewById(R.id.RadioButton01);
    Preference customPref = (Preference) findPreference("customPref");

    customPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){

        public boolean onPreferenceClick(Preference preference) {
            Toast.makeText(getBaseContext(),"The Custom Preference Has Been Clicked",Toast.LENGTH_LONG).show();
            SharedPreferences customSharedPreference = getSharedPreferences("myCutomSharedPrefs", Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor = customSharedPreference.edit();
            editor.putString("myCustomPref","The preference has been clicked");
            editor.commit();
            return true;
        }


        public void CheckBox() {
            final CheckBox ThisCheckBox = (CheckBox) findViewById (R.id.checkboxPref);
            ThisCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
                @Override
               public void onCheckedChanged(CompoundButton compoundButton,boolean test) {
                    if (ThisCheckBox.isChecked()){ 
                        btn01.setVisibility(0);
                    } else {
                        btn01.setVisibility(2);
                    }
                }
            });
        };
    });
}
}

在该线路上产生错误

An error is generated on this line

 public void onCheckedChanged(CompoundButton compoundButton,boolean test) {

他说:

Multiple markers at this line
- The method onCheckedChanged(CompoundButton, boolean) of type new 
 CompoundButton.OnCheckedChangeListener(){} must override a superclass method
- implements 
 android.widget.CompoundButton.OnCheckedChangeListener.onCheckedChanged 

如果我删除@Override注释那么code不工作,并警告告诉我的code中的那部分是不当地使用。

If i remove the @Override annotation then the code doesn't work and a warning tells me that the that part of the code is not used locally.

已经运行在过去的人,并莫名其妙的他们,我在想,如果你能帮忙吗?

Having run this past someone and baffling them I was wondering if you could help?

是否有导致此错误的任何常见情况?

Are there any common scenarios that causes this error?

我想这可能是我的项目设置

I thought it might be my project set up

感谢

推荐答案

这是一个实现的事情。在Java 5比Java 6中,他们改变了你是否能使用覆盖一个接口(因为覆盖似乎暗示要覆盖某种默认行为,你不这样做有一个接口!)。如果你愿意的话,你可以在Eclipse preferences搜索,并从一个编译错误更改为编译警告。您$复选框内C $ C()函数看起来没什么问题。

It's an implementation thing. In Java 5 vs Java 6 they changed whether you could use "Override" with an interface (since Override seems to imply that you are overriding some sort of default behavior, which you are not doing with an interface!). If you so desire, you can search in the Eclipse preferences and change it from a compilation error to a compilation warning. You code inside of the CheckBox() function looks fine to me.

但是,你永远不会调用复选框功能,所以这就是我们所说的不当地使用错误的来源。是你的意思是调用该函数从在preferenceClick方法中?

However, you are never calling the CheckBox function, so that's where the 'not used locally' error is coming from. Were you meaning to call that function from within the OnPreferenceClick method?

这篇关于@Override注释错误(安卓preFS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆