ktina ktina - 2 months ago 29
Android Question

Circular Indicator is not showing below ViewPager android

I am using view pager in my app to images from json data. The json data is coming from rest api. I have deserialize data in controller class. I am using Picasso imgae loader to load the image from json. Now the problem is after running the app, no circular indicator is showing on viewpager. I am not finding the reason why it is showing blank.

My Code to show viewpager is

The code is solved Now

public class OptionMenuFragment extends Fragment implements
NewsController.UserCallbackListener{


private static ViewPager viewPager;
private static int currentPage = 0;


private List<NewsModel> imageList=new ArrayList<>( );
private ViewPagerAdapter adapter;
private NewsController mController;


public OptionMenuFragment() {

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.option_main_fragment, container, false);

viewPager = view.findViewById(R.id.pager);
adapter=new ViewPagerAdapter( this.getActivity(),imageList );
viewPager.setAdapter(adapter);/*(new ViewPagerAdapter( this.getActivity(),XMENArray)*/;
CircleIndicator indicator = (CircleIndicator) view.findViewById(R.id.indicator);
indicator.setViewPager(viewPager);
mController = new NewsController(this);
mController.startFetching();

}


@Override
public void onResume() {
// Auto start of viewpager
handler = new Handler();
Update= new Runnable() {
public void run() {
if (currentPage == imageList.size()) {
currentPage = 0;
}
viewPager.setCurrentItem(currentPage++, true);
System.out.println(viewPager.getCurrentItem());
}
};
swipeTimer = new Timer();
swipeTimer.schedule(new TimerTask() {
@Override
public void run() {
handler.post(Update);
}
},2000,5000);
super.onResume();
}

@Override
public void onPause() {
swipeTimer.cancel();
super.onPause();
}


Layout File

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.1">

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<me.relex.circleindicator.CircleIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"/>
</FrameLayout>

Answer Source

Because you are using dynamic adapter, according to CircleIndicator documentation you will have to put these lines

viewpager.setAdapter(mAdapter);
indicator.setViewPager(viewpager);
mAdapter.registerDataSetObserver(indicator.getDataSetObserver());