无法在查看页程序页面适配器中调用实例化项方法



我在尝试在 Android 活动中制作图像滑块时无法调用实例化项方法。显示没有任何错误,但图像不可见,这是适配器代码:

public class CustomSwipeAdapter extends PagerAdapter
{
    ImageView imageView;
    private int[] image_resources={R.drawable.bus,R.drawable.cp,R.drawable.ty};
    private Context ctx;
    private LayoutInflater layoutInflater;
    @Override
    public int getCount() {
        return 0;
    }
    public CustomSwipeAdapter(Context ctx)
    {
        Log.d("**************","**************5");
        this.ctx=ctx;
    }
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return (view==(LinearLayout)object);
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        Log.d("**************","**************7");
        layoutInflater=(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=layoutInflater.inflate(R.layout.swipe_layout,null);
         imageView=(ImageView)view.findViewById(R.id.image_view1);
        imageView.setImageResource(image_resources[position]);
        ViewPager vp=(ViewPager)container;
        vp.addView(view,0);
        //container.addView(view);
        Log.d("**************","**************8");
        return view;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object)
    {
        ViewPager vp =(ViewPager)container;
        View view=(View)object;
        vp.removeView(view);
        //container.removeView((LinearLayout)object);
    }
}

你在 getCount(( 中返回 0。返回要显示的图像数的长度,如下所示:

@Override
public int getCount() {
    return image_resources.length;
}

相关内容

  • 没有找到相关文章

最新更新