Reputation: 837
I'm developing an app where the main activity consists of a SwipeView layout.
The activity consists of 2000+ pages, which are individually populated by texts, which are in form of short facts.
I want to add a Floating Action Button to those pages which when clicked, will mark the FACT as a favourite, which the user can view later.
How can I implement that without having to add a button to all the pages individually ( which would be impractical and absurd).
Upvotes: 0
Views: 2165
Reputation: 11
You can put your button on the Activity or fragment that holds your ViewPager, instead of on each ViewPager's adapter
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/vpMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:layout_margin="15dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/btn_favorite"/>
</RelativeLayout>
Upvotes: 1