iT邦幫忙

1

PagingSource為何有錯誤=.=?

錯誤語句是這樣
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

尚未有邦友回答

立即登入回答