The method isViewFromObject(View, Object) of type new PagerAdapter(){} must override or implement a supertype method
網上說的方法: 一、
因為你的Compiler 是jdk1.5,只要把它改為 1.6
方法:
1. window ->preferences... -> java -> Compiler
2. Compiler compliance level : 6.0
二、 把項目的JRE變成6.0的
項目右鍵->build path->configure build path->java Compiler(左邊那排中) ->在右邊的Compiler compliance level 修改版本為6.0
試過了沒有作用。
import java.awt.Window;
import java.util.ArrayList;
import java.util.List;
import javax.swing.text.View;
import com.csst.videotalk.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;
public class ViewPaper_activity extends Activity
{
ViewPager mViewPager;
private int[] mImgIds = new int[] { /*R.drawable.guide_image1,
R.drawable.guide_image2, R.drawable.guide_image3 */};
private List mImageViews = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.view_paper);
initData();
mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
mViewPager.setAdapter(new PagerAdapter()
{
@Override
public Object instantiateItem(ViewGroup container, int position)
{
container.addView(mImageViews.get(position));
return mImageViews.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position,
Object object)
{
container.removeView(mImageViews.get(position));
}
@Override
//就是這裡一直報錯
public boolean isViewFromObject(View view, Object object)
{
return view == object;
}
@Override
public int getCount()
{
return mImgIds.length;
}
});
}
private void initData()
{
for (int imgId : mImgIds)
{
ImageView imageView = new ImageView(getApplicationContext());
imageView.setScaleType(ScaleType.CENTER_CROP);
imageView.setImageResource(imgId);
mImageViews.add(imageView);
}
}
}
竟然自己解決了,雖然不知道原因,哈哈哈!!誰能給解釋下;
public boolean isViewFromObject(View view, Object object)
{
return view == object;
}
改成
public boolean isViewFromObject(android.view.View view, Object object)
{
return view == object;
}
就可以了,我是先刪除原來的override,按提示自動添加未重寫的方法,系統自動寫出來的。