0

I'm trying to edit an item in my RecyclerView but I don't know how to pass the information (e.g. position in the list, values it holds) to the EditItem activity. Here is how I'm detecting the tap:

rvBucketItem = (RecyclerView) findViewById(R.id.rvBucketItemList);
ItemList = BucketItem.initializeTaskList(1);
BucketItemAdapter adapterBucket = new BucketItemAdapter(this, ItemList);
rvBucketItem.setAdapter(adapterBucket);
rvBucketItem.setLayoutManager(new LinearLayoutManager(this));

rvBucketItem.setOnClickListener(new RecyclerView.OnClickListener()
{
    @Override
    public void onClick(View view)
    {
        Intent intent = new Intent(MainBucketActivity.this, EditItem.class);
        startActivity(intent);
    }
});

I know that you can store items into the list using the putExtra() method but I don't know how I'd get the items themselves.

Isabel Alphonse
  • 539
  • 1
  • 8
  • 14
  • 1
    you should not use recyclerview.onClickListener method. you need to implement it in your adapter class. see : http://stackoverflow.com/questions/24471109/recyclerview-onclick – okarakose Feb 02 '17 at 18:44
  • Possible duplicate of [What is a "bundle" in an Android application](http://stackoverflow.com/questions/4999991/what-is-a-bundle-in-an-android-application) – Cheesebaron Feb 02 '17 at 18:52
  • @OmerKarakose I tried to but it confused me and gave me dozens of bugs I could not resolve. Like I can't even declare `private final OnClickListener mOnClickListener = new MyOnClickListener();` inside of my adapter class. – Isabel Alphonse Feb 02 '17 at 18:52
  • @Cheesebaron it's not the actual passing that's the problem. Like I said I could just use `putExtra()` but the problem is I need to "get" the information in order to pass it and I don't know how to do that. – Isabel Alphonse Feb 02 '17 at 18:54

2 Answers2

1

please refer below code

rvBucketItem.addOnItemTouchListener(  
    new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
      @Override public void onItemClick(View view, int position) {
        // TODO Handle item click with view and given position
      }
    })
);
Jitesh Mohite
  • 31,138
  • 12
  • 157
  • 147
0

I think you are looking for a Bundle, this way you can transmit Data to the new activity.

Bundles are generally used for passing data between various Android activities. It depends on you what type of values you want to pass, but bundles can hold all types of values and pass them to the new activity.

Here is the link -> What is a "bundle" in an Android application

Community
  • 1
  • 1
Alex
  • 779
  • 7
  • 15
  • Not what I'm looking for. I have no problem passing information I just have a problem getting it to start with. Like how do I know what is the position of the item. – Isabel Alphonse Feb 02 '17 at 18:55