daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Button click works only once #351

Open parassftpl opened 8 years ago

parassftpl commented 8 years ago

I am using SwipeLayout in my activity. Activity is having 2 buttons. On button click, I want to set respective fragment on bottom layout. And on close, it should set replace bottom layout with default fragment so that on swipe it displays default fragment.

When I set default fragment in onClose method of swipeLayout.addSwipeListener, it does not listen to button click.

This works fine with RecyclerView but now I want same in activity

`<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView android:id="@+id/card_view" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" card_view:cardBackgroundColor="@android:color/white" card_view:cardCornerRadius="6dp" card_view:cardElevation="6dp"

xmlns:swipe="http://schemas.android.com/tools">

<com.daimajia.swipe.SwipeLayout
    android:id="@+id/swipe_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- Bottom View Start-->
        <!--What you want to show-->

        <LinearLayout
            android:id="@+id/sub_item_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@android:color/holo_orange_light"></LinearLayout>

    <!-- Bottom View End-->

    <!-- Surface View Start -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/frame_list_card_item"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="9"
            android:background="#eefeef"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:id="@+id/title_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="this is the Title this is the Title this is the Title this is the Title this is the Title "
                android:textColor="#000"
                android:textSize="15sp"/>

            <LinearLayout
                android:id="@+id/container_list_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:animateLayoutChanges="true"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text "
                    android:textSize="13sp"/>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <Button
                        android:id="@+id/btn_one"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minHeight="0dp"
                        android:text="4"/>

                    <Button
                        android:id="@+id/btn_two"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:minHeight="0dp"
                        android:text="5"/>
                </LinearLayout>
            </LinearLayout>

            <!--What you want to show in SurfaceView-->
        </LinearLayout>

    </LinearLayout>

    <!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>

</android.support.v7.widget.CardView>`

`package com.sp.spsamples3.activities;

public class SwipeLayoutActivity extends AppCompatActivity {

SwipeLayout mSwipeLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_swipe_layout);

    mSwipeLayout = (SwipeLayout) findViewById(R.id.swipe_layout);

    getSupportFragmentManager().beginTransaction().replace(R.id.sub_item_container, new DefaultFragment()).commit();
    mSwipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);

    mSwipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
        @Override
        public void onStartOpen(SwipeLayout layout) {

        }

        @Override
        public void onOpen(SwipeLayout layout) {
                                Log.i("sp testing","open");
        }

        @Override
        public void onStartClose(SwipeLayout layout) {
                              Log.i("sp testing","start close");
        }

        @Override
        public void onClose(SwipeLayout layout) {
                              Log.i("sp testing","closed");
            getSupportFragmentManager().beginTransaction().replace(R.id.sub_item_container, new DefaultFragment()).commit();
        }

        @Override
        public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {

        }

        @Override
        public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {

        }
    });
    initClicks();

}

private void initClicks() {

    ((Button) findViewById(R.id.btn_one)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("sp testing", "1 clicked");
            setFragment(new ScreenOneFragment());
            mSwipeLayout.open(true);
        }
    });

    ((Button) findViewById(R.id.btn_two)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("sp testing", "2 clicked");
            setFragment(new ScreenTwoFragment());
            mSwipeLayout.open(true);
        }
    });
}

private void setFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.sub_item_container, fragment).commit();
}

} `

This happens on button click 07-29 15:40:05.258 16442-16442/com.sp.spswipelayoutsample I/sp testing: start close 07-29 15:40:05.258 16442-16442/com.sp.spswipelayoutsample I/sp testing: closed

parassftpl commented 8 years ago

@daimajia can you look into my issue