Open fauzynurn opened 6 years ago
I have two buttons on my swipe layout. they both increment and decrement an integer value whenever they are clicked. But after i click one of the button, the layout close automatically. What is wrong with my code?
Here's some screenshoot :
Swipe layout xml :
<?xml version="1.0" encoding="utf-8"?> <com.daimajia.swipe.SwipeLayout 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" android:id="@+id/swipe" app:leftEdgeSwipeOffset="0dp" app:rightEdgeSwipeOffset="0dp" android:layout_width="match_parent" android:layout_height="88dp">
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/bottom_wrapper" android:orientation="horizontal" android:background="@drawable/item_swipe_bg"> <Button android:layout_width="42dp" android:layout_marginTop="18dp" android:id="@+id/minus_btn" android:layout_marginLeft="119dp" android:layout_height="42dp" android:background="@drawable/minus_btn_pressable"/> <TextView android:layout_width="wrap_content" android:layout_marginLeft="181dp" android:textSize="20sp" android:id="@+id/qty_ordered" android:layout_marginTop="26dp" android:textColor="@color/white" android:layout_height="wrap_content" android:fontFamily="@font/agbold" android:text="1"/> <Button android:layout_width="42dp" android:layout_marginTop="18dp" android:layout_marginLeft="212dp" android:id="@+id/plus_btn" android:layout_height="42dp" android:background="@drawable/plus_btn_pressable"/> </RelativeLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/menu_bg"> <TextView android:id="@+id/menu_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginStart="98dp" android:layout_marginTop="15dp" android:fontFamily="@font/usbold" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/black" android:textSize="17sp" tools:text="Food name" /> <com.jcminarro.roundkornerlayout.RoundKornerRelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="24dp" android:layout_marginTop="10dp" app:corner_radius="35dp"> <ImageView android:layout_width="55dp" android:layout_height="55dp" android:src="@drawable/nasgor" android:id="@+id/food_img" android:scaleType="fitXY" /> </com.jcminarro.roundkornerlayout.RoundKornerRelativeLayout> <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignStart="@+id/menu_name" android:layout_below="@+id/menu_name" android:fontFamily="@font/mentonesb" android:text="price" android:textColor="#393939" /> </RelativeLayout> </com.daimajia.swipe.SwipeLayout>
My itemholder class :
public class MenuItemHolder extends RecyclerView.ViewHolder { public SwipeLayout swipeLayout; public TextView foodName,price,qtyOrdered; public Button plusBtn,minusBtn; private int qtyContainer = 1; // public ImageView imgSrc; public MenuItemHolder(View view) { super(view); plusBtn = view.findViewById(R.id.plus_btn); minusBtn = view.findViewById(R.id.minus_btn); qtyOrdered = itemView.findViewById(R.id.qty_ordered); foodName = view.findViewById(R.id.menu_name); price = view.findViewById(R.id.price); // imgSrc = view.findViewById(R.id.bg_food); swipeLayout = view.findViewById(R.id.swipe); swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); //dari kiri swipeLayout.addDrag(SwipeLayout.DragEdge.Right, swipeLayout.findViewById(R.id.bottom_wrapper)); swipeLayout.addDrag(SwipeLayout.DragEdge.Left, null); plusBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { qtyContainer++; qtyOrdered.setText(String.valueOf(qtyContainer)); swipeLayout.open(); } }); minusBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { qtyContainer--; if(qtyContainer < 1){ qtyContainer = 1; } qtyOrdered.setText(String.valueOf(qtyContainer)); swipeLayout.open(); } }); } }
Any help will be appreciated. Thanks :)
UPDATE : The main problem is the setText method which makes the swipe layout close. so, where should i put the setText method?
@fauzynurn I have similar issue, when view inside swipelayout is starting animate swipelayout close itself
I have two buttons on my swipe layout. they both increment and decrement an integer value whenever they are clicked. But after i click one of the button, the layout close automatically. What is wrong with my code?
Here's some screenshoot :
Swipe layout xml :
<?xml version="1.0" encoding="utf-8"?> <com.daimajia.swipe.SwipeLayout 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" android:id="@+id/swipe" app:leftEdgeSwipeOffset="0dp" app:rightEdgeSwipeOffset="0dp" android:layout_width="match_parent" android:layout_height="88dp">
My itemholder class :
Any help will be appreciated. Thanks :)
UPDATE : The main problem is the setText method which makes the swipe layout close. so, where should i put the setText method?