I am facing issue in get response in kotlin. My json response is:
{
"message":"Success",
"status":false,
"data":[
{
"id":"1",
"username":"doctor",
"phone":null,
"speciality":"General Physician",
"name":"Doctor",
"firstname":null,
"lastname":null,
"gender":"",
"age":null,
"dobirth":null,
"email":"[email protected]",
"country":"Pakistan",
"state":"Punjab",
"city":"Lahore",
"address":null,
"affiliation":"",
"degree":"MBBS",
"bio":null,
"password":"$2y$10$KF1zBxe07nPBW.0hFWiFfOjIur4cYYfP.LlQlujjcHq4WmQMLGWLK",
"remember_token":"UlekRgPJqWPx9AczdW2D7cyjiWkyU4mDpGYkR2QYovjsDCaVTt7adnQmSJQo",
"image":"1496739459-ariba.jpg",
"license_owner":"0",
"status":"0",
"switch_role":"1",
"invitation_code":"",
"created_at":"2018-10-01 07:55:47",
"updated_at":"2018-01-26 00:02:50",
"license_purchase_id":"0",
"profile_active":"0",
"pmdc":"",
"flag":"1"
},
{
"id":"2",
"username":"khawarshah",
"phone":null,
"speciality":"",
"name":"Syed Khawar",
"firstname":null,
"lastname":null,
"gender":"",
"age":null,
"dobirth":null,
"email":"[email protected]",
"country":"",
"state":"",
"city":"",
"address":null,
"affiliation":"",
"degree":"",
"bio":null,
"password":"$2y$10$3nG\/43tUdA2QKzinBPvA4.zqQHfxmR8sZ0LICQ3xg6LLr6mFYZq7q",
"remember_token":"teuzY7HKubHdQg9TXA3zgDJmszrNPm2vBg1226JmDPhk0APZuEafIUpNGKJ4",
"image":"",
"license_owner":"0",
"status":"1",
"switch_role":"1",
"invitation_code":"",
"created_at":"2019-04-19 07:08:10",
"updated_at":"2019-04-19 11:08:10",
"license_purchase_id":"0",
"profile_active":"0",
"pmdc":"",
"flag":"1"
}
]
}
ApiClient class and ApiFactory is
data class Users (
@Expose
@SerializedName("message")
val message: String,
@Expose
@SerializedName("status")
val status: String,
@Expose
@SerializedName("id")
val id: String,
@Expose
@SerializedName("username")
val username: String,
@Expose
@SerializedName("speciality")
val speciality: String,
@Expose
@SerializedName("firstname")
val firstname: String,
@Expose
@SerializedName("name")
val name: String,
@Expose
@SerializedName("lastname")
val lastname: String,
@Expose
@SerializedName("gender")
val gender: String,
@Expose
@SerializedName("age")
val age: String,
@Expose
@SerializedName("dobirth")
val dobirth: String,
@Expose
@SerializedName("email")
val email: String,
@Expose
@SerializedName("image")
val image: String,
@Expose
@SerializedName("switch_role")
val switch_role: String
)
And Main fragment is
class HomeFragment : Fragment() {
private lateinit var homeViewModel: HomeViewModel
lateinit var progerssProgressDialog: ProgressDialog
var dataList = ArrayList<Users>()
lateinit var recyclerView: RecyclerView
lateinit var adapter:ListAdapter
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
homeViewModel =
ViewModelProviders.of(this).get(HomeViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_home, container, false)
val RecyclerView: RecyclerView = root.findViewById(R.id.recyclerView)
recyclerView = root.findViewById(R.id.recyclerView)
recyclerView.adapter= ListAdapter(dataList,requireContext())
recyclerView.layoutManager=LinearLayoutManager(requireContext(),LinearLayoutManager.VERTICAL,false)
progerssProgressDialog=ProgressDialog(requireContext())
progerssProgressDialog.setTitle("Loading")
progerssProgressDialog.setCancelable(false)
progerssProgressDialog.show()
getData()
return root
}
private fun getData() {
val call: Call<List<Users>> = ApiClient.getClient.getPhotos()
call.enqueue(object : Callback<List<Users>> {
override fun onResponse(call: Call<List<Users>>?, response: Response<List<Users>>?) {
progerssProgressDialog.dismiss()
dataList.addAll(response!!.body()!!)
recyclerView.adapter?.notifyDataSetChanged()
}
override fun onFailure(call: Call<List<Users>>, t: Throwable) {
progerssProgressDialog.dismiss()
}
})
}
}
but did not get response in recyclerview. what is the mistake?
