Closed vickymessii closed 4 years ago
I have Placed buttons into item_spot.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:foreground="?attr/selectableItemBackground" app:cardUseCompatPadding="true" app:cardPreventCornerOverlap="false" app:cardCornerRadius="8dp" app:cardBackgroundColor="@android:color/white"> <com.makeramen.roundedimageview.RoundedImageView android:id="@+id/item_image" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" app:riv_corner_radius="8dp"/> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:padding="16dp" android:background="@drawable/gradation_black"> <TextView android:id="@+id/item_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:fontFamily="@font/latobold" android:textColor="@android:color/white" android:textSize="26sp"/> <TextView android:id="@+id/item_city" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:fontFamily="@font/latobold" android:textColor="@android:color/white" android:textSize="20sp"/> <LinearLayout android:id="@+id/button_container" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="80dp" android:layout_alignParentBottom="true" android:paddingBottom="5dp" android:clipChildren="false" android:clipToPadding="false"> <RelativeLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:paddingRight="16dp" android:paddingEnd="16dp" android:clipToPadding="false"> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/skip_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:hapticFeedbackEnabled="true" android:src="@drawable/skip_red_24dp" app:backgroundTint="@android:color/white" app:fabSize="auto" app:rippleColor="#22ED7563"/> </RelativeLayout> <RelativeLayout android:orientation="horizontal" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:paddingLeft="16dp" android:paddingStart="16dp" android:clipToPadding="false"> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/like_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:hapticFeedbackEnabled="true" android:src="@drawable/like_green_24dp" app:backgroundTint="@android:color/white" app:fabSize="auto" app:rippleColor="#226FE2B3"/> </RelativeLayout> </LinearLayout> </LinearLayout> <FrameLayout android:id="@+id/left_overlay" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/overlay_black"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/skip_white_120dp" android:layout_gravity="center"/> </FrameLayout> <FrameLayout android:id="@+id/right_overlay" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/overlay_black"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/like_white_120dp" android:layout_gravity="center"/> </FrameLayout> <FrameLayout android:id="@+id/top_overlay" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> <FrameLayout android:id="@+id/bottom_overlay" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </androidx.cardview.widget.CardView>
But can't call like button
@Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final Spot spot = spots.get(position); holder.name.setText(spot.name); holder.city.setText(spot.city); Glide.with(holder.image).load(spot.url).into(holder.image); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(v.getContext(), spot.name, Toast.LENGTH_SHORT).show(); } }); holder.like_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SwipeAnimationSetting setting = new SwipeAnimationSetting.Builder() .setDirection(Direction.Left) .setDuration(200) .setInterpolator(new AccelerateInterpolator()) .build(); manager.setSwipeAnimationSetting(setting); cardStackView.swipe(); } }); }
Able to manage call activity method in Adapter
I have Placed buttons into item_spot.xml
But can't call like button