我在cardView中创建了一个切换按钮,当按下切换按钮时,它应该将cardItem复制到另一个片段。我为toggleButton做了这个:
//reverse the list, return new list
List* reverseList(List &listToReverse) {
//dynamic memory allocation
List* newList = new List;
//pointer to first node
Node* currentPtr = listToReverse.getFirstNode();
while (currentPtr != 0) {
newList->AddElement(currentPtr->getdata());
currentPtr = currentPtr->getNextPtr();
}
Node* currentNode = newList->getFirstNode();
int size = newList->size();
while (currentNode != 0) {
currentNode->setId(size);
size--;
currentNode = currentNode->getNextPtr();
}
return newList;
}
int main() {
List l1;
cout << "The reversed list: " << endl;
reverseList(l1)->print();
system("pause");
return 0;
}
这就是我想要检索我放置的值的地方。
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);
}
});
我应该用什么来替换它来初始化cardItems? (*仅显示按下了toogle按钮的卡片)
答案 0 :(得分:0)
您是否想知道如何通过意图将Serializable数据传递给另一个片段? 如果是这样,它会对你有所帮助 Passing data through intent using Serializable
如果没有,请详细告诉我。谢谢。