From 491d9f770fa74f51df6c50b8967810ae136ec2f1 Mon Sep 17 00:00:00 2001 From: xuexiangjys Date: Thu, 17 Nov 2022 23:41:05 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E5=88=87=E5=88=86=E5=87=BA=E5=88=86?= =?UTF-8?q?=E6=94=AF1.2.1"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a09bb815 --- app/build.gradle | 4 +-- .../recyclerview/XRecyclerAdapter.java | 27 +++++-------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 58ff9339..ccde0d5f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,8 +14,8 @@ android { applicationId "com.xuexiang.xuidemo" minSdkVersion 17 targetSdkVersion build_versions.target_sdk - versionCode 22 - versionName "1.2.1" + versionCode 21 + versionName "1.2.0" multiDexEnabled true vectorDrawables.useSupportLibrary = true diff --git a/xui_lib/src/main/java/com/xuexiang/xui/adapter/recyclerview/XRecyclerAdapter.java b/xui_lib/src/main/java/com/xuexiang/xui/adapter/recyclerview/XRecyclerAdapter.java index 2c315613..aff5daf5 100644 --- a/xui_lib/src/main/java/com/xuexiang/xui/adapter/recyclerview/XRecyclerAdapter.java +++ b/xui_lib/src/main/java/com/xuexiang/xui/adapter/recyclerview/XRecyclerAdapter.java @@ -78,9 +78,9 @@ public XRecyclerAdapter(T[] data) { /** * 构建自定义的ViewHolder * - * @param parent 父布局 - * @param viewType view类型 - * @return ViewHolder + * @param parent + * @param viewType + * @return */ @NonNull protected abstract V getViewHolder(@NonNull ViewGroup parent, int viewType); @@ -88,7 +88,7 @@ public XRecyclerAdapter(T[] data) { /** * 绑定数据 * - * @param holder ViewHolder + * @param holder * @param position 索引 * @param item 列表项 */ @@ -99,7 +99,7 @@ public XRecyclerAdapter(T[] data) { * * @param parent 父布局 * @param layoutId 布局ID - * @return 加载的布局 + * @return */ protected View inflateView(ViewGroup parent, @LayoutRes int layoutId) { return LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false); @@ -113,8 +113,7 @@ public V onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - final int position = getItemPosition(holder); - mClickListener.onItemClick(holder.itemView, getItem(position), position); + mClickListener.onItemClick(holder.itemView, getItem(holder.getLayoutPosition()), holder.getLayoutPosition()); } }); } @@ -122,8 +121,7 @@ public void onClick(View v) { holder.itemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - final int position = getItemPosition(holder); - mLongClickListener.onItemLongClick(holder.itemView, getItem(position), position); + mLongClickListener.onItemLongClick(holder.itemView, getItem(holder.getLayoutPosition()), holder.getLayoutPosition()); return true; } }); @@ -131,17 +129,6 @@ public boolean onLongClick(View v) { return holder; } - /** - * 获取item的位置,这里默认使用getLayoutPosition来进行获取,可以重写这个方法 - * - * @param holder ViewHolder - * @return 位置 - */ - protected int getItemPosition(V holder) { - return holder.getLayoutPosition(); - } - - @Override public void onBindViewHolder(@NonNull V holder, int position) { bindData(holder, position, mData.get(position));