Skip to content

Commit

Permalink
添加item长按事件
Browse files Browse the repository at this point in the history
  • Loading branch information
shehuan committed Jun 13, 2019
1 parent 7a533a3 commit 1ae97ac
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ private void scrollLoadMore() {
if (isReset) {
return;
}
if (!isLoading && isAutoLoadMoreEnd){
addFooterView(mLoadingView);
}

if (mFooterLayout.getChildAt(0) == mLoadingView && !isLoading) {
if (mLoadMoreListener != null) {
isLoading = true;
Expand Down Expand Up @@ -526,12 +524,12 @@ public void setOnLoadMoreListener(OnLoadMoreListener loadMoreListener) {
* 重置adapter,恢复到初始状态
*/
public void reset() {
if (mLoadingView != null && !isAutoLoadMoreEnd) {
if (mLoadingView != null) {
addFooterView(mLoadingView);
}
isLoading = false;
isReset = true;
// isAutoLoadMoreEnd = false;
isAutoLoadMoreEnd = false;
mDatas.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.othershe.baseadapter.ViewHolder;
import com.othershe.baseadapter.interfaces.OnItemChildClickListener;
import com.othershe.baseadapter.interfaces.OnItemClickListener;
import com.othershe.baseadapter.interfaces.OnItemLongClickListener;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -19,6 +20,7 @@
*/
public abstract class CommonBaseAdapter<T> extends BaseAdapter<T> {
private OnItemClickListener<T> mItemClickListener;
private OnItemLongClickListener<T> mItemLongClickListener;

private ArrayList<Integer> mItemChildIds = new ArrayList<>();
private ArrayList<OnItemChildClickListener<T>> mItemChildListeners = new ArrayList<>();
Expand Down Expand Up @@ -61,6 +63,16 @@ public void onClick(View view) {
}
});

viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (mItemLongClickListener != null) {
mItemLongClickListener.onItemLongClick(viewHolder, getAllData().get(position), position);
}
return true;
}
});

for (int i = 0; i < mItemChildIds.size(); i++) {
final int tempI = i;
if (viewHolder.getConvertView().findViewById(mItemChildIds.get(i)) != null) {
Expand All @@ -83,6 +95,10 @@ public void setOnItemClickListener(OnItemClickListener<T> itemClickListener) {
mItemClickListener = itemClickListener;
}

public void setOnItemLongClickListener(OnItemLongClickListener<T> itemLongClickListener) {
mItemLongClickListener = itemLongClickListener;
}

public void setOnItemChildClickListener(int viewId, OnItemChildClickListener<T> itemChildClickListener) {
mItemChildIds.add(viewId);
mItemChildListeners.add(itemChildClickListener);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.othershe.baseadapter.interfaces;

import com.othershe.baseadapter.ViewHolder;

/**
* Author: SheHuan
* Time: 2019/6/13 16:48
*/
public interface OnItemLongClickListener<T> {
void onItemLongClick(ViewHolder viewHolder, T data, int position);
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ allprojects {
**2. 添加项目依赖**
``` gradle
dependencies {
implementation 'com.github.SheHuan:RecyclerViewAdapter:1.2.6'
implementation 'com.github.SheHuan:RecyclerViewAdapter:1.2.9'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.othershe.baseadapter.interfaces.OnItemClickListener;
import com.othershe.baseadapter.ViewHolder;
import com.othershe.baseadapter.interfaces.OnItemLongClickListener;
import com.othershe.baseadapter.interfaces.OnLoadMoreListener;

import java.util.ArrayList;
Expand Down Expand Up @@ -63,6 +64,13 @@ public void onItemClick(ViewHolder viewHolder, String data, int position) {
}
});

mAdapter.setOnItemLongClickListener(new OnItemLongClickListener<String>() {
@Override
public void onItemLongClick(ViewHolder viewHolder, String data, int position) {
Toast.makeText(CommonItemActivity.this, "长按事件", Toast.LENGTH_SHORT).show();
}
});

WrapLinearLayoutManager layoutManager = new WrapLinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
Expand Down Expand Up @@ -91,7 +99,7 @@ public void run() {
}, 100);
}

public void shuaxin(View view){
public void shuaxin(View view) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit 1ae97ac

Please sign in to comment.