diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/AnimationUseActivity.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/AnimationUseActivity.java index d2b64a5d5..8c4849038 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/AnimationUseActivity.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/AnimationUseActivity.java @@ -18,6 +18,7 @@ import com.chad.baserecyclerviewadapterhelper.utils.Tips; import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.listener.OnItemChildClickListener; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.jaredrummler.materialspinner.MaterialSpinner; import com.kyleduo.switchbutton.SwitchButton; @@ -58,11 +59,11 @@ private void initAdapter() { int mFirstPageItemCount = 3; // mAnimationAdapter.setNotDoAnimationCount(mFirstPageItemCount); mAnimationAdapter.addChildClickViewIds(R.id.img, R.id.tweetName, R.id.tweetText); - mAnimationAdapter.setOnItemChildClickListener(new OnItemChildClickListener() { + mAnimationAdapter.setOnItemChildClickListener(new OnItemChildClickListener() { @Override - public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { String content = null; - Status status = (Status) adapter.getItem(position); + Status status = adapter.getItem(position); switch (view.getId()) { case R.id.img: content = "img:" + status.getUserAvatar(); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DataBindingUseActivity.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DataBindingUseActivity.java index 0266485ae..45896046e 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DataBindingUseActivity.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DataBindingUseActivity.java @@ -9,10 +9,12 @@ import com.chad.baserecyclerviewadapterhelper.R; import com.chad.baserecyclerviewadapterhelper.adapter.DataBindingAdapter; import com.chad.baserecyclerviewadapterhelper.base.BaseActivity; +import com.chad.baserecyclerviewadapterhelper.databinding.ItemMovieBinding; import com.chad.baserecyclerviewadapterhelper.entity.Movie; import com.chad.baserecyclerviewadapterhelper.utils.Tips; import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.listener.OnItemClickListener; +import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder; import java.util.ArrayList; import java.util.List; @@ -48,9 +50,9 @@ protected void onCreate(Bundle savedInstanceState) { adapter.addHeaderView(view); //item 点击事件 - adapter.setOnItemClickListener(new OnItemClickListener() { + adapter.setOnItemClickListener(new OnItemClickListener>() { @Override - public void onItemClick(BaseQuickAdapter adapter, View view, int position) { + public void onItemClick(BaseQuickAdapter> adapter, View view, int position) { Tips.show("onItemClick: " + position); } }); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DragAndSwipeUseActivity.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DragAndSwipeUseActivity.java index d1c3d68b2..4202c5917 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DragAndSwipeUseActivity.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/DragAndSwipeUseActivity.java @@ -128,9 +128,9 @@ public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, mRecyclerView.setAdapter(mAdapter); - mAdapter.setOnItemClickListener(new OnItemClickListener() { + mAdapter.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { Tips.show("点击了:" + position); } }); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HeaderAndFooterUseActivity.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HeaderAndFooterUseActivity.java index 4da663e1f..89462c905 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HeaderAndFooterUseActivity.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HeaderAndFooterUseActivity.java @@ -11,9 +11,11 @@ import com.chad.baserecyclerviewadapterhelper.R; import com.chad.baserecyclerviewadapterhelper.adapter.HeaderAndFooterAdapter; import com.chad.baserecyclerviewadapterhelper.base.BaseActivity; +import com.chad.baserecyclerviewadapterhelper.entity.Status; import com.chad.baserecyclerviewadapterhelper.utils.Tips; import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.listener.OnItemClickListener; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; /** * https://github.com/CymChad/BaseRecyclerViewAdapterHelper @@ -100,9 +102,9 @@ private void initAdapter() { adapter = new HeaderAndFooterAdapter(PAGE_SIZE); adapter.setAnimationEnable(true); - adapter.setOnItemClickListener(new OnItemClickListener() { + adapter.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { Tips.show(String.valueOf(position)); } diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HomeActivity.kt b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HomeActivity.kt index 456c086bc..1c9695486 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HomeActivity.kt +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/HomeActivity.kt @@ -12,8 +12,9 @@ import com.chad.baserecyclerviewadapterhelper.databinding.ActivityHomeBinding import com.chad.baserecyclerviewadapterhelper.entity.HomeEntity import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.listener.OnItemClickListener +import com.chad.library.adapter.base.viewholder.BaseViewHolder -class HomeActivity : AppCompatActivity(), OnItemClickListener { +class HomeActivity : AppCompatActivity(), OnItemClickListener { private lateinit var binding: ActivityHomeBinding @@ -30,8 +31,8 @@ class HomeActivity : AppCompatActivity(), OnItemClickListener { } } - override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) { - val item = adapter.data[position] as HomeEntity + override fun onItemClick(adapter: BaseQuickAdapter, view: View, position: Int) { + val item = adapter.data[position] if (!item.isHeader) { startActivity(Intent(this@HomeActivity, item.activity)) } diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/ItemClickActivity.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/ItemClickActivity.java index 7e688a4c1..cf664ace7 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/ItemClickActivity.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/ItemClickActivity.java @@ -18,6 +18,7 @@ import com.chad.library.adapter.base.listener.OnItemChildLongClickListener; import com.chad.library.adapter.base.listener.OnItemClickListener; import com.chad.library.adapter.base.listener.OnItemLongClickListener; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; import java.util.ArrayList; import java.util.List; @@ -41,28 +42,28 @@ protected void onCreate(Bundle savedInstanceState) { mRecyclerView = findViewById(R.id.rv); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); initAdapter(); - adapter.setOnItemClickListener(new OnItemClickListener() { + adapter.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { Tips.show("onItemClick " + position); } }); - adapter.setOnItemLongClickListener(new OnItemLongClickListener() { + adapter.setOnItemLongClickListener(new OnItemLongClickListener() { @Override - public boolean onItemLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public boolean onItemLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { Tips.show("onItemLongClick " + position); return true; } }); - adapter.setOnItemChildClickListener(new OnItemChildClickListener() { + adapter.setOnItemChildClickListener(new OnItemChildClickListener() { @Override - public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { Tips.show("onItemChildClick " + position); } }); - adapter.setOnItemChildLongClickListener(new OnItemChildLongClickListener() { + adapter.setOnItemChildLongClickListener(new OnItemChildLongClickListener() { @Override - public boolean onItemChildLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public boolean onItemChildLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { Tips.show("onItemChildLongClick " + position); return true; } diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/SectionQuickUseActivity.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/SectionQuickUseActivity.java index be5aaf444..2a0145dae 100644 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/SectionQuickUseActivity.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/activity/SectionQuickUseActivity.java @@ -18,6 +18,7 @@ import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.listener.OnItemChildClickListener; import com.chad.library.adapter.base.listener.OnItemClickListener; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; import java.util.List; @@ -43,9 +44,9 @@ protected void onCreate(Bundle savedInstanceState) { mData = DataServer.getSectionData(); SectionQuickAdapter adapter = new SectionQuickAdapter(R.layout.item_section_content, R.layout.def_section_head, mData); - adapter.setOnItemClickListener(new OnItemClickListener() { + adapter.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { MySection mySection = mData.get(position); if (mySection.isHeader()) { Tips.show((String) mySection.getObject()); @@ -55,9 +56,9 @@ public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, i } } }); - adapter.setOnItemChildClickListener(new OnItemChildClickListener() { + adapter.setOnItemChildClickListener(new OnItemChildClickListener() { @Override - public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { + public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) { Tips.show("onItemChildClick: " + position); } }); diff --git a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/ItemClickAdapter.java b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/ItemClickAdapter.java index 35a9c5d83..8fd1167d1 100755 --- a/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/ItemClickAdapter.java +++ b/app/src/main/java/com/chad/baserecyclerviewadapterhelper/adapter/ItemClickAdapter.java @@ -8,6 +8,7 @@ import com.chad.baserecyclerviewadapterhelper.R; import com.chad.baserecyclerviewadapterhelper.entity.ClickEntity; +import com.chad.baserecyclerviewadapterhelper.entity.Status; import com.chad.baserecyclerviewadapterhelper.utils.Tips; import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter; @@ -20,7 +21,7 @@ /** * */ -public class ItemClickAdapter extends BaseMultiItemQuickAdapter implements OnItemClickListener, OnItemChildClickListener { +public class ItemClickAdapter extends BaseMultiItemQuickAdapter implements OnItemClickListener, OnItemChildClickListener { public ItemClickAdapter(List data) { super(data); @@ -73,12 +74,12 @@ protected void convert(@NonNull final BaseViewHolder helper, final ClickEntity i } @Override - public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { + public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { Tips.show("childView click"); } @Override - public void onItemClick(BaseQuickAdapter adapter, View view, int position) { + public void onItemClick(BaseQuickAdapter adapter, View view, int position) { Tips.show("嵌套RecycleView item 收到: " + "点击了第 " + position + " 一次"); } } diff --git a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt index e87f7adda..17c8eb908 100644 --- a/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt +++ b/library/src/main/java/com/chad/library/adapter/base/BaseQuickAdapter.kt @@ -133,10 +133,10 @@ abstract class BaseQuickAdapter private var mLastPosition = -1 private var mSpanSizeLookup: GridSpanSizeLookup? = null - private var mOnItemClickListener: OnItemClickListener? = null - private var mOnItemLongClickListener: OnItemLongClickListener? = null - private var mOnItemChildClickListener: OnItemChildClickListener? = null - private var mOnItemChildLongClickListener: OnItemChildLongClickListener? = null + private var mOnItemClickListener: OnItemClickListener? = null + private var mOnItemLongClickListener: OnItemLongClickListener? = null + private var mOnItemChildClickListener: OnItemChildClickListener? = null + private var mOnItemChildLongClickListener: OnItemChildLongClickListener? = null private var mUpFetchModule: BaseUpFetchModule? = null private var mDraggableModule: BaseDraggableModule? = null internal var mLoadMoreModule: BaseLoadMoreModule? = null @@ -1335,27 +1335,27 @@ abstract class BaseQuickAdapter this.mSpanSizeLookup = spanSizeLookup } - fun setOnItemClickListener(listener: OnItemClickListener?) { + fun setOnItemClickListener(listener: OnItemClickListener?) { this.mOnItemClickListener = listener } - fun setOnItemLongClickListener(listener: OnItemLongClickListener?) { + fun setOnItemLongClickListener(listener: OnItemLongClickListener?) { this.mOnItemLongClickListener = listener } - fun setOnItemChildClickListener(listener: OnItemChildClickListener?) { + fun setOnItemChildClickListener(listener: OnItemChildClickListener?) { this.mOnItemChildClickListener = listener } - fun setOnItemChildLongClickListener(listener: OnItemChildLongClickListener?) { + fun setOnItemChildLongClickListener(listener: OnItemChildLongClickListener?) { this.mOnItemChildLongClickListener = listener } - fun getOnItemClickListener(): OnItemClickListener? = mOnItemClickListener + fun getOnItemClickListener(): OnItemClickListener? = mOnItemClickListener - fun getOnItemLongClickListener(): OnItemLongClickListener? = mOnItemLongClickListener + fun getOnItemLongClickListener(): OnItemLongClickListener? = mOnItemLongClickListener - fun getOnItemChildClickListener(): OnItemChildClickListener? = mOnItemChildClickListener + fun getOnItemChildClickListener(): OnItemChildClickListener? = mOnItemChildClickListener - fun getOnItemChildLongClickListener(): OnItemChildLongClickListener? = mOnItemChildLongClickListener + fun getOnItemChildLongClickListener(): OnItemChildLongClickListener? = mOnItemChildLongClickListener } diff --git a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildClickListener.java b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildClickListener.java index a1002a558..6a1a9bdea 100644 --- a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildClickListener.java +++ b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildClickListener.java @@ -1,17 +1,19 @@ package com.chad.library.adapter.base.listener; + import android.view.View; import androidx.annotation.NonNull; import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; /** * @author: limuyang * @date: 2019-12-03 * @Description: */ -public interface OnItemChildClickListener { +public interface OnItemChildClickListener { /** * callback method to be invoked when an item child in this view has been click * @@ -19,5 +21,5 @@ public interface OnItemChildClickListener { * @param view The view whihin the ItemView that was clicked * @param position The position of the view int the adapter */ - void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); + void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); } diff --git a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildLongClickListener.java b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildLongClickListener.java index a9392400c..9e0055fc9 100644 --- a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildLongClickListener.java +++ b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemChildLongClickListener.java @@ -5,13 +5,14 @@ import androidx.annotation.NonNull; import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; /** * @author: limuyang * @date: 2019-12-03 * @Description: */ -public interface OnItemChildLongClickListener { +public interface OnItemChildLongClickListener { /** * callback method to be invoked when an item in this view has been * click and held @@ -21,5 +22,5 @@ public interface OnItemChildLongClickListener { * @param position The position of the view int the adapter * @return true if the callback consumed the long click ,false otherwise */ - boolean onItemChildLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); + boolean onItemChildLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); } diff --git a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemClickListener.java b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemClickListener.java index 946caad4a..2584d901c 100644 --- a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemClickListener.java +++ b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemClickListener.java @@ -5,6 +5,7 @@ import androidx.annotation.NonNull; import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; /** * @author: limuyang @@ -12,7 +13,7 @@ * @Description: Interface definition for a callback to be invoked when an item in this * RecyclerView itemView has been clicked. */ -public interface OnItemClickListener { +public interface OnItemClickListener { /** * Callback method to be invoked when an item in this RecyclerView has * been clicked. @@ -22,5 +23,5 @@ public interface OnItemClickListener { * will be a view provided by the adapter) * @param position The position of the view in the adapter. */ - void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); + void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); } diff --git a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemLongClickListener.java b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemLongClickListener.java index ddccea4d1..545d8e428 100644 --- a/library/src/main/java/com/chad/library/adapter/base/listener/OnItemLongClickListener.java +++ b/library/src/main/java/com/chad/library/adapter/base/listener/OnItemLongClickListener.java @@ -5,13 +5,14 @@ import androidx.annotation.NonNull; import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; /** * @author: limuyang * @date: 2019-12-03 * @Description: */ -public interface OnItemLongClickListener { +public interface OnItemLongClickListener { /** * callback method to be invoked when an item in this view has been * click and held @@ -21,5 +22,5 @@ public interface OnItemLongClickListener { * @param position The position of the view int the adapter * @return true if the callback consumed the long click ,false otherwise */ - boolean onItemLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); + boolean onItemLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position); }