【问题标题】:ImageView of Cards in a deck卡片组中卡片的 ImageView
【发布时间】:2021-05-04 07:29:36
【问题描述】:

我正在开发一款卡片游戏(不是“52 张卡片组”)。你必须从DeckChooseFragment 中为你的牌组选择 10 张牌。可以正常工作(选择的卡片存储在名为 DeckArrayList 中)。

在另一个Fragment DeckFragment 我想要显示这10张选择的卡片。我有每张卡片的图片。在DeckFragment 我有10 个ImageViews

我该怎么办,DeckFragment 中只有这 10 张卡片显示在我的ImageViews 中?

这些卡片被称为“1;2;3;4;等等”。在Deck

【问题讨论】:

    标签: java arrays android-studio arraylist imageview


    【解决方案1】:

    在打开 DeckFragment 之前,将卡片 ID 列表放入 Bundle 并通过 arguments 属性提供:

    DeckFragment().apply {
        arguments = bundleOf("cardIds" to "1; 2; 3; 4;")
    }
    // open the fragment afterwards
    

    然后在 DeckFragment 中:

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        arguments?.getString("cardIds")?.let {
            // load the list of images based on the given ids
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 2018-08-06
      • 2021-08-12
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      相关资源
      最近更新 更多