androidandroid-viewpagerandroid-pageradapter

Moving view pager to first item when the end of view pager is reached


Following is my instantiateItem method

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

        ImageView imageView = (ImageView) itemView.findViewById(R.id.img);
        TextView textView = (TextView) itemView.findViewById(R.id.txt);
        imageView.setImageResource(mResources[position]);
        textView.setText(mCompanies[position]);
        container.addView(itemView);

        return itemView;
    }

I want to detect if user has reached the end of view pager by scrolling and if the user has reached the end, I wanna shake the entire viewpager from left to right. How can I do so?


Solution

  • @Override
    public void onPageScrollStateChanged(int state) {
    
         //mImageResource is image array
    
        if(state<mImageResources.length)
        {
       //intro_images is viewpager           
       intro_images.setCurrentItem(0,true);
        }
    
    }