Package com.example.qrgo.utilities
Class CarouselAdapter
- java.lang.Object
-
- androidx.viewpager.widget.PagerAdapter
-
- com.example.qrgo.utilities.CarouselAdapter
-
public class CarouselAdapter extends androidx.viewpager.widget.PagerAdapter
An adapter class for displaying a list of QR codes in a carousel format using a ViewPager.This adapter extends PagerAdapter to handle the swipe functionality.
-
-
Constructor Summary
Constructors Constructor Description CarouselAdapter(android.content.Context context, java.util.List<BasicQRCode> carouselItems)
Constructs a new CarouselAdapter object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroyItem(android.view.ViewGroup container, int position, java.lang.Object object)
This method is called when the item instantiated byinstantiateItem(ViewGroup, int)
is no longer needed and should be removed from the container.int
getCount()
Returns the number of QR codes in the carousel.java.lang.Object
instantiateItem(android.view.ViewGroup container, int position)
Creates a new view for a QR code in the carousel.boolean
isViewFromObject(android.view.View view, java.lang.Object object)
Determines if a given view is associated with a given object.-
Methods inherited from class androidx.viewpager.widget.PagerAdapter
destroyItem, finishUpdate, finishUpdate, getItemPosition, getPageTitle, getPageWidth, instantiateItem, notifyDataSetChanged, registerDataSetObserver, restoreState, saveState, setPrimaryItem, setPrimaryItem, startUpdate, startUpdate, unregisterDataSetObserver
-
-
-
-
Constructor Detail
-
CarouselAdapter
public CarouselAdapter(android.content.Context context, java.util.List<BasicQRCode> carouselItems)
Constructs a new CarouselAdapter object.- Parameters:
context
- The context of the current state of the application.carouselItems
- The list of BasicQRCode objects to be displayed in the carousel.
-
-
Method Detail
-
getCount
public int getCount()
Returns the number of QR codes in the carousel.- Specified by:
getCount
in classandroidx.viewpager.widget.PagerAdapter
- Returns:
- The number of QR codes in the carousel.
-
isViewFromObject
public boolean isViewFromObject(android.view.View view, java.lang.Object object)
Determines if a given view is associated with a given object.- Specified by:
isViewFromObject
in classandroidx.viewpager.widget.PagerAdapter
- Parameters:
view
- The view to be compared with the object.object
- The object to be compared with the view.- Returns:
- True if the view is associated with the object, false otherwise.
-
instantiateItem
public java.lang.Object instantiateItem(android.view.ViewGroup container, int position)
Creates a new view for a QR code in the carousel.- Overrides:
instantiateItem
in classandroidx.viewpager.widget.PagerAdapter
- Parameters:
container
- The parent view where the new view will be attached.position
- The position of the QR code in the carousel.- Returns:
- The new view for the QR code.
-
destroyItem
public void destroyItem(android.view.ViewGroup container, int position, java.lang.Object object)
This method is called when the item instantiated byinstantiateItem(ViewGroup, int)
is no longer needed and should be removed from the container. In this case, it removes the view associated with the specified position.- Overrides:
destroyItem
in classandroidx.viewpager.widget.PagerAdapter
- Parameters:
container
- The containingViewGroup
from which the item will be removed.position
- The position of the item within the adapter's data set that is being removed.object
- TheObject
representing the view to be removed.
-
-