0

How to add dots indicators to my project. I tried many tutorials and solutions, but all solutions required to add fragments to my project which i don't want.

SlideAdapter.java

public class SlideAdapter extends PagerAdapter {

Context context;
LayoutInflater inflater;


public int[] lst_images = {
        R.drawable.iconslide1,
        R.drawable.iconslide2,
        R.drawable.iconslide3,
        R.drawable.iconslide2
};

public String[] lst_title = {
        "COSMONAUT",
        "SATELITE",
        "GALAXY",
        "ROCKET"
}   ;

public String[] lst_description = {
        "a",
        "b",
        "c",
        "d"
};

public int[]  lst_backgroundcolor = {
        Color.rgb(55,55,55),
        Color.rgb(239,85,85),
        Color.rgb(110,49,89),
        Color.rgb(1,188,212)
};
public SlideAdapter(Context context) {
    this.context = context;
}

@Override
public int getCount() {
    return lst_title.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
    return (view==(LinearLayout)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
    inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.slide , container , false);
    LinearLayout layoutslide = (LinearLayout) v.findViewById(R.id.slidelinearlayout);
    ImageView imgslide = (ImageView)  v.findViewById(R.id.slideimg);
    TextView txttitle= (TextView) v.findViewById(R.id.txttitle);
    TextView description = (TextView) v.findViewById(R.id.txtdescription);
    layoutslide.setBackgroundColor(lst_backgroundcolor[position]);
    imgslide.setImageResource(lst_images[position]);
    txttitle.setText(lst_title[position]);
    description.setText(lst_description[position]);
    container.addView(v);
    return v;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((LinearLayout)object);
}}

and there what i did in my main_Slider java class

main_Slider.java

 private ViewPager viewPager;
    private SlideAdapter myadapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.slide_main);
        viewPager = (ViewPager) findViewById(R.id.viewpager);
        myadapter = new SlideAdapter(this);
        viewPager.setAdapter(myadapter);}

so i need modify my codes to add dots indicators.

ColdFire
  • 6,764
  • 6
  • 35
  • 51
jassim
  • 9
  • 1
  • 6
  • 2
    Possible duplicate of [How do you create an Android View Pager with a dots indicator?](https://stackoverflow.com/questions/38459309/how-do-you-create-an-android-view-pager-with-a-dots-indicator) – AskNilesh Apr 27 '18 at 10:42
  • I followed this tutorial it gave me error in tabLayout.setupWithViewPager(pager, true); – jassim Apr 27 '18 at 10:45
  • What's the error? – Mike M. Apr 27 '18 at 10:47
  • cannot resolve setupWithViewPager(viewPager, true); – jassim Apr 27 '18 at 10:57
  • can u print the error in u your question?Also please update your answer with whole code. – DevKRos Apr 27 '18 at 11:16
  • If you're using an old version of the support library, it possibly doesn't have the `setupWithViewPager()` overload that takes a `boolean` as a second argument. You could remove that `true` argument, or upgrade to a newer version. – Mike M. Apr 27 '18 at 11:26
  • [refer this link it will help you](https://github.com/ongakuer/CircleIndicator) – Hardik Vasani Apr 28 '18 at 05:27

0 Answers0