【发布时间】:2021-10-15 12:40:53
【问题描述】:
这就是我在这里编写代码的方式。这里有 13 个数据类。我该如何处理这些?我该如何解决这个错误?
我的数据类: //
data class ProfileResponse(
val call_permit: CallPermit,
val educations: List<Education>,
val languages: List<Language>,
val profile: List<Profile>,
val skills: List<Skill>,
val trainings: List<Training>,
val work_experience: List<WorkExperience>
)
我的 apiServiceClass:
@GET("call/profile/{postNumber}")
suspend fun getProfileShow(
@Path("postNumber") number:String
):Response<ProfileResponse>
存储库:
suspend fun getProfileShow(number: String): Response<ProfileResponse> {
return apiService.getProfileShow(number)
}
视图模型类:
val
response:MutableLiveData<Response<ProfileResponse>>=MutableLiveData()
fun getProfileShow(number : String) =viewModelScope.launch{
val res = repository.getProfileShow(number)
response.value=res
}
主类:
viewModel.getProfileShow(ques.user_id)
viewModel.response.observe(viewLifecycleOwner, Observer { response ->
if(response.isSuccessful){
binding.profileSurename.text=response.body()?.toString()
}else {
Toast.makeText(requireContext(), response.code(), Toast.LENGTH_SHORT).show()
}
})
【问题讨论】:
标签: android android-studio kotlin mvvm retrofit