Skip to content

Commit

Permalink
Changes that affect the long press of events on headView and footView
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen authored and Allen committed Aug 6, 2016
1 parent 429c2d7 commit 0d3b752
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 91 deletions.
44 changes: 3 additions & 41 deletions README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class QuickAdapter extends BaseQuickAdapter<Status> {
}
}
```
#设置 item click
Adapter
```java
mRecyclerView.addOnItemTouchListener(new OnItemClickListener(mRecyclerView,mQuickAdapter){
Expand All @@ -76,6 +75,7 @@ mRecyclerView.addOnItemTouchListener(new OnItemClickListener(mRecyclerView,mQuic
});

```
#设置 item click 新增添加子布局多个控件的点击事件
#设置 it item child click
首先需要添加需要点击触发的 childview id
```
Expand All @@ -92,7 +92,7 @@ mRecyclerView.addOnItemTouchListener(new OnItemClickListener(mRecyclerView,mQuic
Glide.with(mContext).load(item.getUserAvatar()).crossFade().placeholder(R.mipmap.def_head).transform(new GlideCircleTransform(mContext)).into((ImageView) helper.getView(R.id.tweetAvatar));
}
```
然后
Activity
```java
mRecyclerView.addOnItemTouchListener(new OnItemChildClickListener(mRecyclerView,mQuickAdapter) {
@Override
Expand Down Expand Up @@ -162,45 +162,7 @@ mRecyclerView.addOnItemTouchListener(new OnItemClickListener(mRecyclerView,mQuic
});
```

![addOnItemTouchListener](http://7xs9qs.com1.z0.glb.clouddn.com/B001F6D5-E057-4202-9312-8953D9B60E18.png)
#如果需要给 childView 设置点击事件
```
helper.addOnClickListener(R.id.tweetAvatar)
.addOnClickListener(R.id.tweetName);
```
#如何添加item点击、长按事件
![demo](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/blob/master/demo_res/chlid_click.gif)
```java
mQuickAdapter.setOnRecyclerViewItemClickListener();
mQuickAdapter.setOnRecyclerViewItemLongClickListener();
```
#新增添加子布局多个控件的点击事件
Adapter
```java
protected void convert(BaseViewHolder helper, Status item) {
helper.setOnClickListener(R.id.tweetAvatar, new OnItemChildClickListener())
.setOnClickListener(R.id.tweetName, new OnItemChildClickListener());
}
```
Activity
```java
mQuickAdapter.setOnRecyclerViewItemChildClickListener(new BaseQuickAdapter.OnRecyclerViewItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
String content = null;
Status status = (Status) adapter.getItem(position);
switch (view.getId()) {
case R.id.tweetAvatar:
content = "img:" + status.getUserAvatar();
break;
case R.id.tweetName:
content = "name:" + status.getUserName();
break;
}
Toast.makeText(AnimationUseActivity.this, content, Toast.LENGTH_LONG).show();
}
});
```

#如何使用它添加动画?
![demo](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/blob/master/demo_res/animation.gif)
```java
Expand Down
37 changes: 6 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# BaseRecyclerViewAdapterHelper([中文版文档](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/blob/master/README-cn.md)
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/972352-1d77e0a75a4a7c0a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Powerful and flexible RecyclerAdapter
Please feel free to use this.(Love can be a **Star**)
Please feel free to use this.(Welcome to **Star** and **Fork**)
## Google Play Demo

[![Get it on Google Play](https://developer.android.com/images/brand/en_generic_rgb_wo_60.png)](https://play.google.com/store/apps/details?id=com.chad.baserecyclerviewadapterhelper)
Expand Down Expand Up @@ -73,7 +73,7 @@ mRecyclerView.addOnItemTouchListener(new OnItemClickListener(mRecyclerView,mQuic

```
#Use it item child click
first you should add child view id
first you should register child view id
```
@Override
protected void convert(BaseViewHolder helper, Status item) {
Expand Down Expand Up @@ -110,7 +110,7 @@ and then
});
```
#use it item child long click
first you should add child view id
Adapter
```
@Override
protected void convert(BaseViewHolder helper, Status item) {
Expand All @@ -125,7 +125,7 @@ first you should add child view id
Glide.with(mContext).load(item.getUserAvatar()).crossFade().placeholder(R.mipmap.def_head).transform(new GlideCircleTransform(mContext)).into((ImageView) helper.getView(R.id.tweetAvatar));
}
```
and then
Activity
```java
mRecyclerView.addOnItemTouchListener(new OnItemChildLongClickListener(mRecyclerView,mQuickAdapter) {
@Override
Expand All @@ -135,6 +135,7 @@ and then
});
```
#if you wish to implement various forms of click
Activity
```java
mRecyclerView.addOnItemTouchListener(new SimpleClickListener(mRecyclerView, mQuickAdapter) {
@Override
Expand All @@ -159,33 +160,7 @@ and then
});
```

#Use it item chlid click
Adapter
```java
protected void convert(BaseViewHolder helper, Status item) {
helper.setOnClickListener(R.id.tweetAvatar, new OnItemChildClickListener())
.setOnClickListener(R.id.tweetName, new OnItemChildClickListener());
}
```
Activity
```java
mQuickAdapter.setOnRecyclerViewItemChildClickListener(new BaseQuickAdapter.OnRecyclerViewItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
String content = null;
Status status = (Status) adapter.getItem(position);
switch (view.getId()) {
case R.id.tweetAvatar:
content = "img:" + status.getUserAvatar();
break;
case R.id.tweetName:
content = "name:" + status.getUserName();
break;
}
Toast.makeText(AnimationUseActivity.this, content, Toast.LENGTH_LONG).show();
}
});
```


#Use it add adaptar Animation
![demo](https://github.com/CymChad/BaseRecyclerViewAdapterHelper/blob/master/demo_res/animation.gif)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RecyclerClickItemActivity extends Activity {

private RecyclerView mRecyclerView;
private QuickClickAdapter mQuickAdapter;
private static final int PAGE_SIZE = 100;
private static final int PAGE_SIZE = 10;
private static String TAG = "RecyclerClickItemActivity";

@Override
Expand All @@ -31,8 +31,8 @@ protected void onCreate(Bundle savedInstanceState) {
mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
initAdapter();
mQuickAdapter.addHeaderView(getView());
mQuickAdapter.addFooterView(getView());
mQuickAdapter.addHeaderView(getHeadView());
mQuickAdapter.addFooterView(getFootView());
mRecyclerView.setAdapter(mQuickAdapter);
/**
* Item clcik
Expand All @@ -50,10 +50,10 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)
super.onItemChildClick(adapter, view, position);
switch (view.getId()) {
case R.id.tweetAvatar:
Toast.makeText(RecyclerClickItemActivity.this, "R.id.tweetAvatar click" + Integer.toString(position), Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position)+" tweetAvatar is clicked", Toast.LENGTH_SHORT).show();
break;
case R.id.tweetName:
Toast.makeText(RecyclerClickItemActivity.this, "R.id.tweetName click" + Integer.toString(position), Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this, "The " + Integer.toString(position)+" tweetName is clicked", Toast.LENGTH_SHORT).show();
break;
default:
break;
Expand All @@ -64,14 +64,14 @@ public void onItemChildClick(BaseQuickAdapter adapter, View view, int position)
@Override
public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
super.onItemLongClick(adapter, view, position);
Toast.makeText(RecyclerClickItemActivity.this, "ItemLongClick" + Integer.toString(position), Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this,"The " + Integer.toString(position)+ " Item is LongClick ", Toast.LENGTH_SHORT).show();

}

@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
super.onItemChildLongClick(adapter, view, position);
Toast.makeText(RecyclerClickItemActivity.this, view.getId() + " getLongClick" + Integer.toString(position), Toast.LENGTH_SHORT).show();
Toast.makeText(RecyclerClickItemActivity.this, "The "+ Integer.toString(position)+" view itemchild " + "is LongClick " + Integer.toString(position), Toast.LENGTH_SHORT).show();

}
});
Expand Down Expand Up @@ -122,19 +122,30 @@ public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int positi
});*/
}

private View getView() {
private View getHeadView() {
View view = getLayoutInflater().inflate(R.layout.head_view, null);
view.findViewById(R.id.tv).setVisibility(View.GONE);
view.setLayoutParams(new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(RecyclerClickItemActivity.this, "click View", Toast.LENGTH_LONG).show();
Toast.makeText(RecyclerClickItemActivity.this, "click headView", Toast.LENGTH_LONG).show();
}
});
return view;
}
private View getFootView() {
View view = getLayoutInflater().inflate(R.layout.head_view, null);
view.findViewById(R.id.tv).setVisibility(View.GONE);
view.setLayoutParams(new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(RecyclerClickItemActivity.this, "click FootView", Toast.LENGTH_LONG).show();
}
});
return view;
}

private void initAdapter() {
mQuickAdapter = new QuickClickAdapter(PAGE_SIZE);
mQuickAdapter.openLoadAnimation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,21 @@ public void onLongPress(MotionEvent e) {
View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (child != null) {
BaseViewHolder vh = (BaseViewHolder) recyclerView.getChildViewHolder(child);

longClickViewIds =vh.getItemChildLongClickViewIds();
if (longClickViewIds!=null&&longClickViewIds.size()>0){
for (Iterator it = longClickViewIds.iterator(); it.hasNext(); ) {
View childView = child.findViewById((Integer) it.next());
if (inRangeOfView(childView, e)) {
onItemChildLongClick(baseQuickAdapter,childView, vh.getLayoutPosition() - baseQuickAdapter.getHeaderLayoutCount());
return ;
int type= baseQuickAdapter.getItemViewType(vh.getLayoutPosition());
if (type != EMPTY_VIEW && type != HEADER_VIEW && type != FOOTER_VIEW && type != LOADING_VIEW){
longClickViewIds =vh.getItemChildLongClickViewIds();
if (longClickViewIds!=null&&longClickViewIds.size()>0){
for (Iterator it = longClickViewIds.iterator(); it.hasNext(); ) {
View childView = child.findViewById((Integer) it.next());
if (inRangeOfView(childView, e)) {
onItemChildLongClick(baseQuickAdapter,childView, vh.getLayoutPosition() - baseQuickAdapter.getHeaderLayoutCount());
return ;
}
}
}
onItemLongClick(baseQuickAdapter,child, vh.getLayoutPosition() - baseQuickAdapter.getHeaderLayoutCount());
}
onItemLongClick(baseQuickAdapter,child, vh.getLayoutPosition() - baseQuickAdapter.getHeaderLayoutCount());

}
}

Expand Down

0 comments on commit 0d3b752

Please sign in to comment.