rubensousa / GravitySnapHelper

A SnapHelper that snaps a RecyclerView to an edge.
Apache License 2.0
5k stars 615 forks source link

OnClickListener for Each Item #18

Closed mrad4tech closed 7 years ago

mrad4tech commented 7 years ago

I am trying to put onclick listener for each item in each snap,so for the first position in the spanscenter has different function than that in endsnap and startsnap,I succeeded in adding click listener for each item (code below),but am having same action for item position 1(for example) in the Four snaps


    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public ImageView imageView;
        public TextView nameTextView;
        public TextView ratingTextView;

        public ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            imageView = (ImageView) itemView.findViewById(R.id.imageView);
            nameTextView = (TextView) itemView.findViewById(R.id.nameTextView);
            ratingTextView = (TextView) itemView.findViewById(R.id.ratingTextView);
        }

        @Override
        public void onClick(View v) {
            Log.d("App", mApps.get(getAdapterPosition()).getName());
            if (getAdapterPosition()==0){
                Toast.makeText(itemView.getContext(), "Position: " + Integer.toString(getAdapterPosition()), Toast.LENGTH_LONG).show();

            }
        }
    }
rubensousa commented 7 years ago

I didn't understand the problem, sorry. Can you provide more details?

mosentest commented 7 years ago

**** @