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
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With