Does anyone know how to define an onClickListener in RecyclerView? I've thought about how to define onClick for each item in the Recycler View, and this seems too much of a hassle Is there any other way?
java android android-5.0-lollipop recyclerview
RecyclerView provides touchListener instead of clickListener. If you don't mind that, please refer to https://developer.android.com/intl/ko/reference/android/support/v7/widget/RecyclerView.OnItemTouchListener.html)%EC%97%AC%EA%B8%B0%EC%97%90%EC%84%9C here.
All items as you think if you want onclicklistener onclicklistener to the settings you. In
, recyclerview adapterprivate final OnClickListener mOnClickListener = new MyOnClickListener();
@Override
public MyViewHolder onCreateViewHolder(final ViewGroup parent, final int position) {
View view = LayoutInflater.from(mContext).inflate(R.layout.myview, parent, false);
view.setOnClickListener(mOnClickListener);
return new MyViewHolder(view);
}
And the onClick method
@Override
public void onClick(final View view) {
int itemPosition = mRecyclerView.getChildPosition(view);
String item = mList.get(itemPosition);
Toast.makeText(mContext, item, Toast.LENGTH_LONG).show();
}
You can define it like this.
877 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 Understanding How to Configure Google API Key
567 Who developed the "avformat-59.dll" that comes with FFmpeg?
576 PHP ssh2_scp_send fails to send files as intended
566 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.