如何在android中单击按钮时停止图像滑块

时间:2015-10-26 13:22:47

标签: android

在oncreate方法中,

mCustomPagerAdapter = new CustomPagerAdapter(this);

mViewPager = (ViewPager) findViewById(R.id.pager);
btnstop=(Button)findViewById(R.id.btnstop);
btnstop.setVisibility(View.VISIBLE);
btnstop.setOnClickListener(new OnClickListener() {
    @SuppressLint("NewApi")
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
    }
});
mViewPager.setAdapter(mCustomPagerAdapter);

和我的自定义addapter的代码

class CustomPagerAdapter extends PagerAdapter {
    Context mContext;
    LayoutInflater mLayoutInflater;
    private boolean enabled;

    public CustomPagerAdapter(Context context) {
        mContext = context;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        //  Log.d("fhgfdbgd",""+mResources.length);
        return mResources.length;
    }
    @Override
    public int getItemPosition(Object object) {
        // TODO Auto-generated method stub

        return super.getItemPosition(object);
    }
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((RelativeLayout) object);
    }

    @Override
    public Object instantiateItem(final ViewGroup container, int position) {
        View itemView = mLayoutInflater.inflate(R.layout.pager_item, container, false);

        ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
        imageView.setImageResource(mResources[position]);

        Log.d("position",""+position);
        container.addView(itemView);
        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((RelativeLayout) object);
    }
}

0 个答案:

没有答案