2011-06-19 63 views
4

我已经看到了类似的问题here,我已经添加行 import android.content.res.Configuration;。虽然没有帮助。为什么我无法重写onConfigurationChanged(Configuration)?

我在写一个扩展了AdapterView<Adapter>的类,Eclipse不会让我重载onConfigurationChanged(Configuration)。如AdapterView page in the Android Docs所示,该方法确实存在。那么为什么我不能重写呢?

这是我实现:

import android.content.Context; 
import android.content.res.Configuration; 
import android.view.View; 
import android.widget.Adapter; 
import android.widget.AdapterView; 
public class Foo extends AdapterView<Adapter> { 

    public Foo(Context context) { 
    super(context); 
    // TODO Auto-generated constructor stub 
    } 

    @Override 
    public Adapter getAdapter() { 
    // TODO Auto-generated method stub 
    return null; 
    } 

    @Override 
    public View getSelectedView() { 
    // TODO Auto-generated method stub 
    return null; 
    } 

    @Override 
    public void setAdapter(Adapter adapter) { 
    // TODO Auto-generated method stub 

    } 

    @Override 
    public void setSelection(int position) { 
    // TODO Auto-generated method stub 

    } 

    /* 
    * Error is thrown here... The method onConfigurationChanged(Configuration) of 
    * type Foo must override or implement a supertype method 
    */ 
    @Override 
    protected void onConfigurationChanged(Configuration newConfig) { 
    /* 
    * Error is thrown here... The method onConfigurationChanged(Configuration) is 
    * undefined for the type AdapterView<Adapter> 
    */ 
    super.onConfigurationChanged(newConfig); 
    } 
} 
+0

请出示您的实现 – MByD

+0

这是基本,因为它得到。我有一个全新的类,它扩展了AdapterView 并实现了继承的抽象方法。这就是现在所做的。问题是,当我尝试重写onConfigurationChanged时,出现一个错误,提示该方法对于AdapterView 类型未定义。 – dfetter88

+0

配置中的参数明确导入为android.content.res.Configuration?更改签名要保护onConfigurationChanged(android.content.res.Configuration配置) – planetjones

回答

4

加入View在API级别8 Eclipse中的构建目标(或default.properties目标的命令行)可能被设置为较低API级别。

+0

我想这可能是沿着这些线。谢谢。 – dfetter88

0

onConfigurationChanged仅在视野中的 “自:API等级8”。如果您针对早期版本进行开发,则不存在此类方法,因此您无法覆盖并调用它们。在“活动”中有一个,您可以通过更改延伸到活动来证明您的代码是正确的。这不是因为你想要一个适配器编译ofcourse工作,但作为理念,为您的进口证明,所有这将:)

相关问题