logo
down
shadow

Detect click on RecyclerView outside of items


Detect click on RecyclerView outside of items

By : user17735
Date : November 19 2020, 01:01 AM
I wish did fix the issue. You can subclass RecyclerView and override the dispatchTouchEvent() method to accomplish this. Using the findChildViewUnder() method, we can determine if a touch event occurs outside of the child Views, and use an interface to notify a listener if it is. In the following example, the OnNoChildClickListener interface provides that functionality.
code :
public class TouchyRecyclerView extends RecyclerView
{
    // Depending on how you're creating this View,
    // you might need to specify additional constructors.
    public TouchyRecyclerView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    private OnNoChildClickListener listener;
    public interface OnNoChildClickListener
    {
        public void onNoChildClick();
    }

    public void setOnNoChildClickListener(OnNoChildClickListener listener)
    {
        this.listener = listener;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event)
    {
        // The findChildViewUnder() method returns null if the touch event
        // occurs outside of a child View.
        // Change the MotionEvent action as needed. Here we use ACTION_DOWN
        // as a simple, naive indication of a click.
        if (event.getAction() == MotionEvent.ACTION_DOWN
            && findChildViewUnder(event.getX(), event.getY()) == null)
        {
            if (listener != null)
            {
                listener.onNoChildClick();
            }
        }
        return super.dispatchTouchEvent(event);
    }
}


Share : facebook icon twitter icon
Able to click on two items at the same time in a RecyclerView

Able to click on two items at the same time in a RecyclerView


By : stillspangle
Date : March 29 2020, 07:55 AM
Any of those help My RecyclerView is programmatically add in Java but not in xml. And I try this and it works:
code :
mRecyclerView.setMotionEventSplittingEnabled(false);
android:splitMotionEvents="false"
Need to detect click and touch event on my RecyclerView with row detection

Need to detect click and touch event on my RecyclerView with row detection


By : rishabh
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I've tried to set up a click and toch listener for my RecyclerView with tutorials. But every tutorial I've tried I finaly failed because I've set the RecyclerView up with an other tutorial and all tutorials are looking different. Please can you help me detect click for each row? For example when a user clicks my first row (which is a logout field) it should logout the user from the app. All of my logout actions are working but the click on RecyclerView don't.
code :
    @Override
    public void onBindViewHolder(MySettingHolder holder, int position) {
        // Setting for one entry
        Settings setting = settingList.get(position);

        holder.settingImage.setImageResource(setting.getSettingImageUrl());
        // If the settingSubtitle is empty it should be not visible and just the settingTitle
        if (setting.getSettingSubtitle().equals("")) {
            holder.settingTitle.setText(setting.getSettingTitle());
            holder.settingSubtitle.setVisibility(View.GONE);
        } else {
            holder.settingTitle.setText(setting.getSettingTitle());
            holder.settingSubtitle.setText(setting.getSettingSubtitle());
        }

        holder.type = setting.getType();
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MySettingHolder holder = (MySettingHolder )(v.getTag());
                switch (holder.type) {

                    case 1:                        
                        // do logout
                        break;

                    case 2:                        
                        // do other stuff
                        break;

                    default:
                        break;
                }
            }
        });

        // set viewholder
        holder.itemView.setTag(holder);
    }
public class MySettingHolder extends RecyclerView.ViewHolder {

        public int type;
        public ImageView settingImage;
        public TextView settingTitle, settingSubtitle;

        public MySettingHolder(View view) {
            super(view);
            settingImage = (ImageView) view.findViewById(R.id.settingImage);
            settingTitle = (TextView) view.findViewById(R.id.settingTitle);
            settingSubtitle = (TextView) view.findViewById(R.id.settingSubtitle);
        }
    }
RecyclerView.ViewHolder On Click Items

RecyclerView.ViewHolder On Click Items


By : Wildfire44601
Date : March 29 2020, 07:55 AM
seems to work fine You will implement your OnClick event handler in the Activity/Fragment where instance of your Adapter is created.
This line means you are making the ItemClick event public in your adapter class.
code :
public event EventHandler<PdfAdapterClickEventArgs> ItemClick;
var adapter = new PdfAdapter(data);
adapter.ItemClick += OnItemClick;
   ....
   ....
myRecyclerView. SetAdapter(adapter);
public void OnItemClick(object sender, PdfAdapterClickEventArgs e)
{
   var view = args.View; //this is your view
   Toast.MakeText(this, $"Item Position: {args?.Position}", ToastLength.Short).Show();
}
How to click recyclerview items in Activity?

How to click recyclerview items in Activity?


By : Abhishek Gupta
Date : March 29 2020, 07:55 AM
I wish this help you I've created a horizontal listview of images using recyclerview , when i click on a particular image ,i want change the background image with that image of my activity , but i'm facing the problem, how i can set onItem click for recyclerview items in my mainactivity?? , May be it will help you but I did like this in my code :
code :
RecyclerView recyclerView = findViewById(R.id.recycler);
recyclerView.addOnItemTouchListener(
    new RecyclerItemClickListener(context, recyclerView ,new RecyclerItemClickListener.OnItemClickListener() {
      @Override public void onItemClick(View view, int position) {
        // do whatever
      }

      @Override public void onLongItemClick(View view, int position) {
        // do whatever
      }
    })
);
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;


public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
  private OnItemClickListener mListener;

  public interface OnItemClickListener {
    public void onItemClick(View view, int position);

    public void onLongItemClick(View view, int position);
  }

  GestureDetector mGestureDetector;

  public RecyclerItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) {
    mListener = listener;
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }

        @Override
        public void onLongPress(MotionEvent e) {
            View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
            if (child != null && mListener != null) {
                mListener.onLongItemClick(child, recyclerView.getChildAdapterPosition(child));
            }
        }
    });
}

  @Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
      mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
      return true;
    }
    return false;
  }

  @Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { }

  @Override
  public void onRequestDisallowInterceptTouchEvent (boolean disallowIntercept){}
}
RecyclerView's onClick won't work clicking items, only when you click BETWEEN items: SOLVED

RecyclerView's onClick won't work clicking items, only when you click BETWEEN items: SOLVED


By : user3268058
Date : March 29 2020, 07:55 AM
I hope this helps you . I'm learning Android and I'm testing things with RecyclerView. I wanted to add an OnItemClickListener, I wanted to see if works so I made a Toast appear each time I click on items, but something weird happens, only triggers when I click BETWEEN cards of Recycler, not when I click items. I've been looking for people with the same problem but didn't found anything. , I fixed it! Apparently if you have the attribute:
code :
clickable:true
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org