Skip to content

Commit

Permalink
the demo for issues/28
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-miao committed Aug 26, 2017
1 parent dc5051a commit 66cc060
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
Expand Down Expand Up @@ -71,9 +72,17 @@ public void onChanged() {
touchListener.setOnHeaderClickListener(
new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() {
@Override
public void onHeaderClick(View header, int position, long headerId) {
Toast.makeText(getActivity(), "Header position: " + position + ", id: " + headerId,
Toast.LENGTH_SHORT).show();
public void onHeaderClick(View header, int position, long headerId, MotionEvent e) {
View view = header.findViewById(R.id.tv_for_click);
int left = view.getLeft();
int right = view.getRight();
float x = e.getX();
float y = e.getX();
// just a demo, (x, y) in view
if(x >= left && y <= right) {
Toast.makeText(getActivity(), "Header position: " + position + ", id: " + headerId,
Toast.LENGTH_SHORT).show();
}
}
});
recyclerView.addOnItemTouchListener(touchListener);
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/res/layout/header_view_sticky_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#999999"
android:orientation="vertical"
android:orientation="horizontal"
android:padding="8dp">

<TextView
android:id="@+id/detail_title"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""/>
<TextView
android:id="@+id/tv_for_click"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="for click"/>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class StickyRecyclerHeadersTouchListener implements RecyclerView.OnItemTo
private OnHeaderClickListener mOnHeaderClickListener;

public interface OnHeaderClickListener {
void onHeaderClick(View header, int position, long headerId);
//void onHeaderClick(View header, int position, long headerId);
void onHeaderClick(View header, int position, long headerId, MotionEvent e);
}

public StickyRecyclerHeadersTouchListener(final RecyclerView recyclerView,
Expand Down Expand Up @@ -79,7 +80,7 @@ public boolean onSingleTapUp(MotionEvent e) {
View headerView = mDecor.getHeaderView(mRecyclerView, position);
long headerId = getAdapter().getHeaderId(position);
if(headerId >= 0) {
mOnHeaderClickListener.onHeaderClick(headerView, position, headerId);
mOnHeaderClickListener.onHeaderClick(headerView, position, headerId, e);

headerView.onTouchEvent(e);
return true;
Expand Down

0 comments on commit 66cc060

Please sign in to comment.