Samanalaya2 February 2016

Android ViewPageIndicator inside a Recylerview is not showing

I added a ViewPageIndicator inside recylcerview item, this is recyclerview item layout.

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardBackgroundColor="@color/background"
    card_view:cardCornerRadius="0dp"
    card_view:cardElevation="0dp"
    android:fillViewport="true">

    <LinearLayout
        android:id="@+id/main_container"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="100dp" />

        <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/pager_indicator"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" />

    </LinearLayout>

</android.support.v7.widget.CardView>

ViewPageIndicator is not showing when scrolling down, but when I'm scrolling up it shows on some items, please help.

Answers


Samanalaya2 February 2016

Issue was on the viewpager adapter, i used both FragmentStatePagerAdapter and FragmentPagerAdapter but no sucess. so finally change the adapter to PagerAdapter and my fragment view implemnted in instantiateItem in PagerAdapter

public class FeedImageAdapter extends PagerAdapter {

    private ArrayList<FeedContentGroup> feedContentGroups;

    private Context mContext;

    private LayoutInflater layoutInflater;

    public FeedImageAdapter(Context context, ArrayList<FeedContentGroup> feedContentGroups) {
        this.mContext = context;
        this.feedContentGroups = feedContentGroups;
        layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public Object instantiateItem(ViewGroup collection, int position) {
        View v = layoutInflater.inflate(R.layout.feed_image_view, null);

        ImageView image1 = (ImageView) v.findViewById(R.id.image1);

        FeedContentGroup mFeedContentGroup = feedContentGroups.get(position);

        if (mFeedContentGroup.getContent1() != null && mFeedContentGroup.getContent1().getThumbnail_file_path() != null) {
            Glide.with(mContext).load(mFeedContentGroup.getContent1().getThumbnail_file_path()).into(image1);
        } else {
            image1.setVisibility(View.GONE);
        }

        ((ViewPager) collection).addView(v, 0);
        return v;
    }

    @Override
    public void destroyItem(View collection, int position, Object view) {
        ((ViewPager) collection).removeView((View) view);
    }

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

    @Override
    public int getCount() {
        return feedContentGroups.size();
    }
}

Post Status

Asked in February 2016
Viewed 3,534 times
Voted 13
Answered 1 times

Search




Leave an answer