小编Art*_*rov的帖子

Kotlin 中如何返回两个值?

我现在回国了liveDataName,但我也想回国liveDataImage

fun getProfileInfo(): LiveData<String> {

        val call: Call<UserProfile>? = NetworkService.getInstance()
                .jsonApi
                .getProfile()
        call?.enqueue(object : Callback<UserProfile>{
            override fun onResponse(call: Call<UserProfile>, response: Response<UserProfile>) {
                if (response.isSuccessful) {
                    response.body()?.let {
                        liveDataName.value = it.username
                        liveDataImage.value = it.defaultAvatar
                    }
                }

            }

            override fun onFailure(call: Call<UserProfile>, t: Throwable) {}
        })

        return liveDataName
    }
Run Code Online (Sandbox Code Playgroud)

return-value kotlin android-studio

4
推荐指数
1
解决办法
4290
查看次数

标签 统计

android-studio ×1

kotlin ×1

return-value ×1