Diolor / Swipecards

A Tinder-like Android library to create the swipe cards effect. You can swipe left or right to like or dislike the content.
Apache License 2.0
2.34k stars 583 forks source link

How to remove buttons in layout and use buttons on the card? #155

Closed thofnar closed 8 years ago

thofnar commented 8 years ago

I would like to add the left and right buttons to my actual card rather than being below the card. I have added them to the card in the card layout but now I can't figure out how to access the buttons in my activity. How can I go about this?

I removed the following line:

<include layout="@layout/buttons" />

From the main activity layout:

<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <com.lorentzos.flingswipe.SwipeFlingAdapterView
        android:id="@+id/frame"
        android:background="#d1d1d1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:rotation_degrees="15.5"
        tools:context=".MainActivity"
        android:layout_gravity="top"/>

    <TextView
        android:id="@+id/tv_noJobsLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textStyle="bold"
        android:textSize="18sp"
        android:textColor="#474747"
        android:textAlignment="center"
        tools:text="Nothing Left to Swipe!"
        android:layout_gravity="center" />

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!--<include layout="@layout/buttons" />-->

</merge>

Now in the activity I tried the following (apply is the name of my button):

@OnClick(R.id.apply)
    public void right() {
        /**
         * Trigger the right event manually.
         */
        makeToast(MainActivity.this, "test");
    }

Now when I try to run the project in the emulator, I get the following error message and the app crashes:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lorentzos.swipecards.example/com.lorentzos.swipecards.MainActivity}: java.lang.RuntimeException: Unable to inject views for com.lorentzos.swipecards.MainActivity@4c3946c

I think this has to do with the button not being on the main layout and it being on the actual card? How can I reference the button on the card, so that when it is pressed, it loads the next card?

Thanks for the help!

thofnar commented 8 years ago

Fixed by following this: https://github.com/Diolor/Swipecards/issues/151