0

This may sound a bit complicated but what I want is simple!. I have a RecyclerView and each item has a delete Button. When I press the button in each item, the corresponding item will get removed from RecyclerView. and now I want to show these removed items into another RecyclerView in another layout!

This is my RecyclerView that I remove the items from each ButtonClick:

 holder.Btn_Remove.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mFeedList.remove(newPosition);
                    notifyItemRemoved(newPosition);
                    notifyItemRangeChanged(newPosition,mFeedList.size());
                }
            });

and now I have Other RecyclerView with DataList. i want to add each removed item to be added automatically to this new DataList.

 private void setDataListItems(){
        mDataList.add(new PendingModel("#198" , "Pizza Hut", "Time : 08.00 ","sector 15", currentDateTimeString, OrderStatus.ACTIVE,0.00));

}

Any help would be appreciated!

Pouya Danesh
  • 1,557
  • 2
  • 19
  • 36
Fajar Khan
  • 952
  • 1
  • 12
  • 30

3 Answers3

0

You can do the same to your next RecyclerView. You can add the item to your data set and then call notifyItemInserted passing the position of the new data.

tompee
  • 1,408
  • 1
  • 7
  • 6
0

I am guessing both the objects are same ,i.e, object to be added and removed. In that case You can do sonmethinhg like this, call this setDataListItems(mFeedList.get(newPosition)) before mFeedList.remove(newPosition); this line

and change setDataListItems to like this.

setDataListItems(PendingModel removedItem){
mDataList.add(removedItem))
adapterOfDataList.notifyDataSetChanged();
}
Sunil Sunny
  • 3,949
  • 4
  • 23
  • 53
0

you should store deleted Items for your other activity I think the best solution for you would be adding an extra column to your database let's call it status, and set that field to deleted for those that are deleted.

but the alternative is using SharedPrefrences like this:

SharedPreferences.Editor editor = sharedpreferences.edit();

        editor.putString(Name, n);
        editor.putString(Phone, ph);
        editor.putString(Email, e);
        editor.commit();

and put the code above in your removeItem method in your adapter and afterward get these in your other activity. use this question for more details.

Pouya Danesh
  • 1,557
  • 2
  • 19
  • 36