0

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).

Prateek Prasad
  • 827
  • 2
  • 10
  • 19
  • Please add more details to your question and go through [How do I ask a good question](http://stackoverflow.com/help/how-to-ask) for help. – Ram Feb 08 '15 at 06:33
  • Add it to the activity containing the view pager. – Gil Maimon Feb 08 '15 at 06:34

1 Answers1

1

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>
tio
  • 11
  • 1
  • Ok, but how do i define the state of the button (favorite, not favorite ) ,...also it's a favorite button, and suppose a user wants to favorite fact number 309 how do I store the data about the fact number which user has marked favorite and then later populate those facts on a different activity called "Favorites", keeping in mind i don't have a database of facts , I'm referencing them from a strings.xml file . – Prateek Prasad Feb 08 '15 at 14:10