0

I've created a toggle button in my cardView and when the toggle button is pressed it should copy the cardItem to another fragment. I've done this for toggleButton:

 holder.favButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(CompoundButton favButton, boolean isChecked){
                if (isChecked)
                    favButton.setBackgroundDrawable(ContextCompat.getDrawable(favButton.getContext(),R.mipmap.ic_launcher));
                Intent intent = new Intent(context,FavouriteFragment.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("DATA", (Serializable) cardItems);
                intent.putExtras(bundle);
                context.startActivity(intent);

            }
        });

and this is where i want to retrieve the values that I've put.

private void initializeCardItemList(){
        CardItemModel cardItemModel;
        String[] cardTitles = getResources().getStringArray(R.array.fav_cards);
        String[] cardContents = getResources().getStringArray(R.array.fav_cards_content);
        final int length = cardTitles.length;
        for(int i=0;i<length;i++){
            cardItemModel = new CardItemModel(cardTitles[i],cardContents[i]);
            cardItems.add(cardItemModel);
        }
    } 

With what I should replace this to initialize the cardItems? (* only showing cards in which toogle button is pressed)

1 Answers1

0

Do you want to know how to pass Serializable data to another fragment through intent? If so, it will help you Passing data through intent using Serializable

If not, please let me know in detail. thank you.

Community
  • 1
  • 1
Sunhee
  • 101
  • 8
  • i've already checked that. i wanted to know how to initialize card items. – Kalpana Devkota May 20 '17 at 15:23
  • Do you mean how to initialize card items "in another fragment" where you sent data to? I think it doesn't need to initialize card items in another fragment and just you need to write **Intent intent = this.getIntent(); Bundle bundle = intent.getExtras(); List cardItems = (List)bundle.getSerializable("DATA");**. – Sunhee May 20 '17 at 16:14