为什么我不能覆盖onConfigurationChanged(配置)? [英] Why can't I override onConfigurationChanged(Configuration)?
问题描述
我已经看到了类似的问题<一href=\"http://stackoverflow.com/questions/2032007/why-cant-i-override-onconfigurationchanged\">here,我已经添加行
。它虽然没有帮助。
进口android.content.res.Configuration;
我写一个扩展类适配器视图&LT;适配器&GT;
和Eclipse将不会让我重写 onConfigurationChanged(配置)
。正如在Android文档的适配器视图页面上看到,该方法确实如此存在。那么,为什么我不能覆盖它?
下面是我的实现:
进口android.content.Context;
进口android.content.res.Configuration;
进口android.view.View;
进口android.widget.Adapter;
进口android.widget.AdapterView;
公共类Foo扩展适配器视图&LT;适配器和GT; { 公共美孚(上下文的背景下){
超级(上下文);
// TODO自动生成构造函数存根
} @覆盖
公共适配器getAdapter(){
// TODO自动生成方法存根
返回null;
} @覆盖
公共查看getSelectedView(){
// TODO自动生成方法存根
返回null;
} @覆盖
公共无效setAdapter(适配器适配器){
// TODO自动生成方法存根 } @覆盖
公共无效setSelection(INT位置){
// TODO自动生成方法存根 } / *
*错误在这里...抛出的方法onConfigurationChanged(配置)
* Foo类型必须覆盖或实现超方法
* /
@覆盖
保护无效onConfigurationChanged(配置NEWCONFIG){
/ *
*错误在这里...抛出的方法onConfigurationChanged(配置)是
*未定义类型的适配器视图&LT;适配器和GT;
* /
super.onConfigurationChanged(NEWCONFIG);
}
}
onConfigurationChanged()
加入查看
在API级别8 Eclipse中的构建目标(或 default.properties
目标的命令行)可能被设置为较低的API级别。
I've already seen the similar question here, and I have already added the line
import android.content.res.Configuration;
. It hasn't helped though.
I am writing a class that extends AdapterView<Adapter>
, and Eclipse will not let me override onConfigurationChanged(Configuration)
. As seen in the AdapterView page in the Android Docs, the method does indeed exist. So why can't I override it?
Here is my implementation:
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);
}
}
onConfigurationChanged()
was added to View
in API Level 8. Your build target in Eclipse (or the target in default.properties
for the command line) probably is set to a lower API level.
这篇关于为什么我不能覆盖onConfigurationChanged(配置)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!