-8

I want to open more details when I click on the item using the position and set the datils in the activity.

enter image description here

You can write your suggestion in Java or Kotlin :)

Abdulrahman
  • 301
  • 1
  • 3
  • 12

2 Answers2

1

Create Constructor in adapter class :

  public DataAdapter(List<Pojo> dataList, OnItemClickListener listener) {
            this.dataList = dataList;
            this.listener = listener;
        }

Create OnBindViewHolder() method and get position :

@Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        final Pojo movie = dataList.get(position);

        holder.Showid.setText(movie.getCatagory_id());
        holder.fname.setText(movie.getCatagory_name());
        holder.thumbNail.setImageUrl(movie.getCatagory_thumbnailUrl(), imageLoader);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {
                listener.onItemClick(movie.getSubCatagoryArrayList());
            }

        });
    }

In MainActivity.class create on Interface :

public interface OnItemClickListener {
        void onItemClick(ArrayList<Pojo2> item);
    }
Ali
  • 3,346
  • 4
  • 21
  • 56
0

first of all recyclerView OnClick method to get position of Click item like this method

int position=getAdapterPosition();

than get position of item (like modelArrayList.get(getAdapterPosition());)

than send id to next activity and id to get data in database and set all the details in next activity

final code

  itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position=getAdapterPosition();
               ModelClass model = modelArrayList.get(getAdapterPosition());
              Long id = model.getId();
                Intent i = new Intent(v.getContext(), NextActivity.class);
                i.putExtra("id",id);

                v.getContext().startActivity(i);
            }
        });

and NextActivity code

Long id = getActivity().getIntent().getExtras().getLong("id", 0);
Monali
  • 173
  • 1
  • 6