I tried to use enqueue callback but it shows that as an error like "Type mismatch.
Required: Callback<*List<-Location>>"
and this is exactly what I wrote.
fun searchLocation(searchString: String){
showProgress.value = true
val retrofit = Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create())
.build()
val service = retrofit.create(WeatherNetwork::class.java)
service.getLocation(searchString).enqueue(object : Callback<List<Location>>{
override fun onFailure(call: Call<List<Location>>, t: Throwable) {
}
override fun onResponse(
call: Call<List<Location>>,
response: Response<List<Location>>
) {
}
})
}
May be it'll be more clear with the pic
UPD: WeatherNetwork
const val BASE_URL = "/My API/"
interface WeatherNetwork{
@GET ("search?")
fun getLocation(SearchString : String) : List<Location>
}
>`
– Fred Mar 25 '20 at 09:16