siralam / LoopingViewPager

A ViewPager and PagerAdapter combination that support auto scroll, infinite loop and page indicators.
532 stars 64 forks source link

viewpager does not shows the first item #21

Closed DJDrama closed 4 years ago

DJDrama commented 5 years ago

For ex, i have 5 items and this viewpager at first load, shows 5 items (autoloop and inifite both true).

When it reaches the last item, it just jump immediately to the second item, and loops again. it never shows the first item any more, and also the last item is not visible to the users since the viewpager pops to the second index (thinking the second index as the first index, and ignoring the last index)

siralam commented 5 years ago

Don't quite get what you mean. Can you paste your code?

DJDrama commented 5 years ago

vpAdapter = ViewPagerAdapter(activity!!, vpList, true) vp_auto_rolling.adapter = vpAdapter

internal class ViewPagerAdapter( context: Context, itemList: java.util.ArrayList, isInfinite: Boolean ) : LoopingPagerAdapter(context, itemList, isInfinite) {

    override fun inflateView(viewType: Int, container: ViewGroup, listPosition: Int): View {
        return LayoutInflater.from(context).inflate(R.layout.vp_item_image, container, false)
    }

    override fun bindView(convertView: View, listPosition: Int, viewType: Int) {
        val ivItem = convertView.findViewById<ImageView>(R.id.iv_vp_item)
        Glide.with(context)
            .load(itemList[listPosition].image_url)
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .into(ivItem)
    }

    override fun getCount(): Int {
        return itemList.size
    }
}

this is it! I am using Kotlin by the way. vplist is just a custom datatype ArrayList

siralam commented 4 years ago

Sorry that I missed this issue for a long time.

Not sure if you still need help, but the problem is because you override getCount() in your adapter. If you check its parent you will see it has special handling.

Remove that override and the issue should be solved.

DJDrama commented 4 years ago

@siralam Thanks for the reply. Yeah i already solved that issue before. But still glad to hear from you! have a nice day