iT邦幫忙

1

PagingSource為何有錯誤=.=?

  • 分享至 

  • xImage

錯誤語句是這樣
Type mismatch: inferred type is List? but List<TypeVariable(Value)> was expected

PhotoItem是我的data class PhotoItem()..

class PixabayDataSource(private val context: Context): PagingSource<Int, PhotoItem>() {
val words= arrayOf("cat","rabbit","rainbow").random()
private val _photoListLive= MutableLiveData<List>()
val photoListLive: LiveData<List> get() = _photoListLive
override fun getRefreshKey(state: PagingState<Int, PhotoItem>): Int? {

}
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, PhotoItem> {
    val url="有私人帳號的api網址"
    val x:Any?=null
    val stringRequest=StringRequest(
        Request.Method.GET,
        url,
        Response.Listener {
            _photoListLive.value=Gson().fromJson(it,Pixabay::class.java).hits.toList()
        },
        Response.ErrorListener {  }
    ).also { VolleySingleton.getInstance(context).requestQueue.add(it) }
    val pageNumber = params.key ?: 0
    val response = stringRequest.searchItems(pageNumber)//有問題?
    val prevKey = if (pageNumber > 0) pageNumber - 1 else null
    val nextKey = if (response.items.isNotEmpty()) pageNumber + 1 else null//有問題?
    return LoadResult.Page(
        data = _photoListLive.value,//有問題?
        prevKey = prevKey,
        nextKey = nextKey
    )
}

}

data = _photoListLive.value , 顯示類型不符為何???看了許久.還是不會用DataSource...我是想從圖片網..要練習paging

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答