Skip to content

Commit

Permalink
Merge pull request #175 from a5533348/master
Browse files Browse the repository at this point in the history
Add function for OnItemChildLongClickListener
  • Loading branch information
CymChad authored Jul 20, 2016
2 parents dd92655 + a853809 commit 6748005
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public interface OnRecyclerViewItemLongClickListener {

private OnRecyclerViewItemChildClickListener mChildClickListener;

private OnRecyclerViewItemChildLongClickListener mChildLongClickListener;

/**
* Register a callback to be invoked when childView in this AdapterView has
* been clicked and held
Expand All @@ -246,6 +248,35 @@ public void onClick(View v) {
}
}

/**
* Register a callback to be invoked when childView in this AdapterView has
* been longClicked and held
* {@link OnRecyclerViewItemChildLongClickListener}
*
* @param childLongClickListener The callback that will run
*/
public void setOnRecyclerViewItemChildLongClickListener(OnRecyclerViewItemChildLongClickListener childLongClickListener) {
this.mChildLongClickListener = childLongClickListener;
}

/**
* Interface for ItemChildLongClick
*/
public interface OnRecyclerViewItemChildLongClickListener {
boolean onItemChildLongClick(BaseQuickAdapter adapter, View view, int position);
}

public class OnItemChildLongClickListener implements View.OnLongClickListener {
public RecyclerView.ViewHolder mViewHolder;
@Override
public boolean onLongClick(View v) {
if (mChildLongClickListener != null) {
return mChildLongClickListener.onItemChildLongClick(BaseQuickAdapter.this, v, mViewHolder.getLayoutPosition() - getHeaderViewsCount());
}
return false;
}
}


/**
* Same as QuickAdapter#QuickAdapter(Context,int) but with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ public BaseViewHolder setOnClickListener(int viewId, BaseQuickAdapter.OnItemChil
return this;
}

/**
* Sets the on longClick listener of the view.
* @param viewId
* @param listener
* @return
*/
public BaseViewHolder setOnLongClickListener(int viewId, BaseQuickAdapter.OnItemChildLongClickListener listener) {
View view = getView(viewId);
listener.mViewHolder = this;
view.setOnLongClickListener(listener);
return this;
}

/**
* Sets the on touch listener of the view.
*
Expand Down

0 comments on commit 6748005

Please sign in to comment.