Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page indicator in android

Tags:

android

I have done Gallery View

gallery = (Gallery) findViewById(R.id.gallery1);
    MyAdapter adapter = new MyAdapter(this);
    gallery.setAdapter(adapter);
    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            Intent go = new Intent(Department2.this,
                    tablistclass_item.class);
            if (!larg) {

                go = new Intent(Department2.this, ListClass.class);
            }

            Bundle b = new Bundle();
            b.putString("headername", nameofimage[position]);
            b.putString("whichclass", "department");
            go.putExtras(b);
            startActivity(go);
        }
    });
}

Now how to make page indicator for Gallery view

like image 879
Android Developer Avatar asked Apr 09 '13 09:04

Android Developer


People also ask

How do I use ViewPager on Android?

Implement Swipe Views You can create swipe views using AndroidX's ViewPager widget. To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .

How do you make a page indicator for horizontal RecyclerView?

You can add an indicator by using RecyclerView. ItemDecoration. Just draw some lines or circles at the bottom and use layoutManager. findFirstVisibleItemPosition() to get the current active item.


Video Answer


1 Answers

Constructing an indicator using a Gallery is difficult since you have no reliable way of knowing the index of the item that is currently at the center. Gallery has also been deprecated since API 16.

Instead you can use a ViewPager. It is available through the Android support library for older versions of Android as well.

You can use Jake Wharton's ViewPager Indicator in conjunction with this to get many kinds of indicators for your ViewPager or you can just have a look at the source code and construct your own.

like image 159
Anup Cowkur Avatar answered Sep 20 '22 23:09

Anup Cowkur