0
    class MyPagerAdaptor extends PagerAdapter
{
    LayoutInflater inflater;

    public MyPagerAdaptor(){
        inflater = getLayoutInflater();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mIdList.size();
    }

    @Override
    public Object instantiateItem(ViewGroup viewGroup, int position) {

        // TODO Auto-generated method stub
        /*if(flag)
        {
            mPosToShare = position;
            System.out.println("mPosToShare......: "+mPosToShare);
            flag = false;
        }*/
        System.out.println("instantiateView............."+position);
        View imageLayout = inflater.inflate(R.layout.item_pager_image, viewGroup, false);
        ImageViewTouch imageView = (ImageViewTouch) imageLayout.findViewById(R.id.image);

        try 
        {
            InputStream is = mExpansionFile.getInputStream("worlatlaspronewmaps/"+title[1]+mIdList.get(position)+".jpg");
            //InputStream is1 = mExpansionFile.getInputStream("worlatlaspronewmaps/"+title[1]+mIdList.get(position-1)+".jpg");
            if(is == null)
            {
                is = mExpansionFile.getInputStream("worlatlaspronewmaps/"+title[1]+mIdList.get(position)+".JPG");
            }

            bitmap = BitmapFactory.decodeStream(is,null,bfOptions);
            System.out.println(bitmap);

            imageView.zoomTo(0.5f,50);
            imageView.setImageBitmap(bitmap);

        }  
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        viewGroup.addView(imageLayout,0);
        return imageLayout;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        // TODO Auto-generated method stub
        return (view==object);
    }

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

MyPagerAdaptor 类正在用位图填充 viewpager,因为寻呼机的每个视图都包含一个 imageview,但是当我获得位图的引用时,它给出了不可见的右位图或左位图的引用。我需要可见的位图参考。

4

1 回答 1

0
objectOfViewPager.getCurrentItem();

这将返回从 0 开始索引的当前项目。

编辑:您可以像这样获得对视图的引用,

int index = objectOfViewPager.getCurrentItem();
View view = objectOfViewPager.getChildAt(index);

编辑2:(进一步解释)

由于您要做的就是更改位图,因此您应该这样做:

int index = objectOfViewPager.getCurrentItem();
mIdList.set(index,whateverBitmapyouwant);
objectOfAdapter.notifyDataSetChanged();
于 2013-05-06T11:20:35.917 回答