Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

android - 在RecyclerView外部单击以在RecyclerView行中隐藏ChildView(Click Outside the RecyclerView to Hide ChildView in RecyclerView Row)

I have a simple RecyclerView and when you LongClick a Row in RecyclerView I make a hidden LinearLayout visible on that row.

(我有一个简单RecyclerView ,当你LongClick在连续RecyclerView我做一个隐藏LinearLayout可见该行。)

To do so In my public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) I am using the following

(这样做在我的public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)我正在使用以下内容)

LinearLayout REACTION_LAYOUT = RecyclerItem.FindViewById<LinearLayout>(Resource.Id.reaction_layout);
RecyclerItem.LongClick += (sender, e) => { OnLongClick(REACTION_LAYOUT); };

REACTION_LAYOUT is the layout I am showing using the following

(REACTION_LAYOUT是我使用以下内容显示的布局)

private void OnLongClick(LinearLayout _ReactionLayout)
        {
            try
            {  
                _ReactionLayout.Visibility = ViewStates.Visible;

            }
            catch (Exception X)
            {
                Log.Info("1022585", "CLICK (ERROR) : " + X.Message);
            }
        }

This works as Intended, Now what I want is to HIDE the REACTION_LAYOUT when a user touches anywhere outside the Row which means on other rows in RecyclerView or anywhere else

(这按预期工作,现在我想要的是当用户触摸行外的任何地方时都隐藏REACTION_LAYOUT ,这意味着RecyclerView中的其他行或其他任何地方)

How do I do that?

(我怎么做?)

The approach I tried to use was to detect a touch on parent within my Adapter's OnCreateViewHolder as following

(我尝试使用的方法是在适配器的OnCreateViewHolder检测对parent的触摸,如下所示)

parent.Click += (sender, e) => { OnParentClick(REACTION_LAYOUT); }; 

This works but It disables the scrolling on recycler view.

(这可以工作,但是会禁用“回收者”视图上的滚动。)

What is the best way to achieve this?

(实现此目标的最佳方法是什么?)

EDIT : The activity RecyclerView is the following

(编辑 :活动RecyclerView是以下)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/main_message_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/colorPrimary"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:orientation="vertical"> 
  <include layout="@layout/toolbar_messages"/>   
  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="4.5dp"
      android:layout_marginTop="3dp"
      android:background="@drawable/shadow"/>  
  <RelativeLayout     
    android:layout_width="match_parent"
    android:layout_height="fill_parent">   
  <androidx.recyclerview.widget.RecyclerView
      android:id="@+id/rvMessages"
     android:layout_width="match_parent"
      android:layout_height="wrap_content"         
      android:background="?attr/colorPrimary"      
      android:layout_alignParentTop="true"
    android:paddingBottom="70dp"/>  .......
  ask by Ali translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

THis method call whenever you click on recylerview item

(当您单击recylerview项时,将调用此方法)

itemView.setOnClickListener(v -> {
               // Add your functionalities here

            });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...