captain-miao / RecyclerViewUtils

[DEPRECATED] // RecyclerView Utils:refresh,load more,sticky header,expand,index
276 stars 68 forks source link

Not Able to perform onClick event #28

Open viswakarmalovekush opened 7 years ago

viswakarmalovekush commented 7 years ago

hi, I want to perform onClick event on Headers Items, so how can i do it, with this library.

captain-miao commented 7 years ago
        // Add touch listeners
        StickyRecyclerHeadersTouchListener touchListener =
                new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor);
        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();
                    }
                });
        recyclerView.addOnItemTouchListener(touchListener);
viswakarmalovekush commented 7 years ago

I want to perform click or touch on the Header Items not on entire header.

waiting for response.

Thanks

On Mon, Aug 21, 2017 at 5:51 PM, yan_lu notifications@github.com wrote:

    // Add touch listeners
    StickyRecyclerHeadersTouchListener touchListener =
            new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor);
    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();
                }
            });
    recyclerView.addOnItemTouchListener(touchListener);

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/captain-miao/RecyclerViewUtils/issues/28#issuecomment-323730255, or mute the thread https://github.com/notifications/unsubscribe-auth/AILOppRneTSr6opygAcYWABmAK6d5lj8ks5saXZngaJpZM4NpdRL .

captain-miao commented 7 years ago

It's work, setOnClickListener() in HeaderItemViewHolder~

    public class HeaderItemViewHolder extends RecyclerView.ViewHolder {
        public TextView mTvTitle;

        public HeaderItemViewHolder(View view) {
            super(view);
            mTvTitle = (TextView) view.findViewById(R.id.detail_title);
            mTvTitle.setOnClickListener(this);
        }
    }

If you can identify by clicking on the coordinates, it can also be:

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

touchListener.setOnHeaderClickListener(
            new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() {
                @Override
                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();
                    }
                }
            });