RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1314688
Accepted
Ethernets
Ethernets
Asked:2022-08-06 14:39:52 +0000 UTC2022-08-06 14:39:52 +0000 UTC 2022-08-06 14:39:52 +0000 UTC

将对象放入改造 2 列表中

  • 772

如何将对象名称添加到列表中,以便通过适配器进一步显示。这是我通过 Retrofit 2 获得的 API 查询列表

接下来,我提出这样的请求:

测试英雄.kt

data class TestHero (@SerializedName("global") val global: PlayerInf,
                     @SerializedName("legends")val legends: AllLegends)

data class  PlayerInf (val name: String, val uid: Long, val avatar: String, val platform: String,
val  level: Int, val toNextLevelPercent: Int, val internalUpdateCount: Int, val bans: BanInf, val rank: RankInf)

data class BanInf (val isActive: Boolean, val remainingSeconds: Int)

data class RankInf (val rankScore: Int, val rankName: String, val rankDiv: Int, val rankImg: String)

data class AllLegends (val all: Revenant)

data class Revenant (val ImgAssets: String)
data class Horizon (val data : ArrayList<Rang>, val ImgAssets: String)

data class Rang (val t0 : String)

也就是说,我需要创建每个对象Revenant, Horizon, Crypto等。但我不明白如何在 textView 的适配器中显示这些名称

HeroesAdapter.kt

class HeroesAdapter(context: Context, heroes: List<TestHero>): BaseAdapter() {
    private val context = context
    private val heroes = heroes

    override fun getCount(): Int {
        return heroes.count()
    }

    override fun getItem(position: Int): Any {
        return heroes[position]
    }

    override fun getItemId(position: Int): Long {
        return 0
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {

           // categoryView = LayoutInflater.from(context).inflate(R.layout.activity_heroes, null)
        val listheroView = LayoutInflater.from(context).inflate(R.layout.list_hero_view, parent, false)
           // val categoryImage: ImageView = categoryView.findViewById(R.id.heroesImageView)
            val heroText: TextView = listheroView.findViewById(R.id.textHeroView)
            val category = heroes[position]

            heroText.text = category.legends.all.toString()
            return listheroView

    }
}

在显示中,我得到以下信息: ListView 中的响应

我想得到的一个例子: 列表

在哪里,点击后,我已经从数据中接收数据

JSON-API

"legends": {
        "selected": {
            "LegendName": "Octane",
            "data": [
                {
                    "name": "Special event kills",
                    "value": 815,
                    "key": "specialEvent_kills"
                },
                {
                    "name": "Special event wins",
                    "value": 37,
                    "key": "specialEvent_wins"
                },
                {
                    "name": "Special event damage",
                    "value": 321873,
                    "key": "specialEvent_damage"
                }
            ],
            "gameInfo": {
                "skin": "Arachnoid Rush",
                "skinRarity": "Legendary",
                "frame": "Shark Teeth",
                "frameRarity": "Legendary",
                "pose": "All. Day.",
                "poseRarity": "Rare",
                "intro": "Death catches up to everyone",
                "introRarity": "Rare",
                "badges": [
                    {
                        "name": "Venomous",
                        "value": 0,
                        "category": "Octane"
                    },
                    {
                        "name": "Wild Frontier Level: Season 1",
                        "value": 112,
                        "category": "Account Badges"
                    },
                    {
                        "name": "Fortune's Favor Level: Season 5",
                        "value": 113,
                        "category": "Account Badges"
                    }
                ]
            },
            "ImgAssets": {
                "icon": "https:\/\/api.mozambiquehe.re\/assets\/icons\/octane.png",
                "banner": "https:\/\/api.mozambiquehe.re\/assets\/banners\/octane.jpg"
            }
        },
        "all": {
            "Revenant": {
                "ImgAssets": {
                    "icon": "https:\/\/api.mozambiquehe.re\/assets\/icons\/revenant.png",
                    "banner": "https:\/\/api.mozambiquehe.re\/assets\/banners\/revenant.jpg"
                }
            },
            "Crypto": {
                "ImgAssets": {
                    "icon": "https:\/\/api.mozambiquehe.re\/assets\/icons\/crypto.png",
                    "banner": "https:\/\/api.mozambiquehe.re\/assets\/banners\/crypto.jpg"
                }
            },
            "Horizon": {
                "data": [
                    {
                        "name": "Season 7 wins",
                        "value": 1,
                        "key": "wins_season_7",
                        "rank": {
                            "rankPos": 59006,
                            "topPercent": 69.87
                        },
                        "rankPlatformSpecific": {
                            "rankPos": 53782,
                            "topPercent": 69.14
                        }
                    },
                    {
                        "name": "Special event kills",
                        "value": 101,
                        "key": "specialEvent_kills",
                        "rank": {
                            "rankPos": 77442,
                            "topPercent": 64.21
                        },
                        "rankPlatformSpecific": {
                            "rankPos": 52573,
                            "topPercent": 60.51
                        }
                    },
                    {
                        "name": "Special event damage",
                        "value": 47004,
                        "key": "specialEvent_damage",
                        "rank": {
                            "rankPos": 74182,
                            "topPercent": 57.92
                        },
                        "rankPlatformSpecific": {
                            "rankPos": 51199,
                            "topPercent": 54.54
                        }
                    }
                ],
                "ImgAssets": {
                    "icon": "https:\/\/api.mozambiquehe.re\/assets\/icons\/horizon.png",
                    "banner": "https:\/\/api.mozambiquehe.re\/assets\/banners\/horizon.jpg"
                }
            },
android
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Ethernets
    2022-08-21T20:06:49Z2022-08-21T20:06:49Z

    为了实现我的解决方案,感谢@woesss 的提示,我将数据解析为Map

    data class AllLegends (@SerializedName("all") val all: Map<String, LegendWrapper> = emptyMap())
    
    
    data class LegendWrapper(
        val data: List<PlayerPerformance>? = emptyList()
    
    )
    data class PlayerPerformance(val name: String, val value: Int, val key: String)
    
    data class TestList (val name: ArrayList<String>) 
    

    然后我在RecyclerView中全部展示了,你可以看这里的实现

    • 1

相关问题

  • 来自片段的列表落后于 BottomNavigationView

  • 无法将变量从 Activity 传递到 Fragment

  • 构建与完成的片段略有不同的片段的最佳方法是什么?

  • 如何更改来自服务器的响应中的日期格式?

  • 谷歌地图在应用程序的发布版本中不起作用

  • 材料设计按钮。单击按钮上的可选区域!

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5