Я пытаюсь получить данные из интернета, после завершения я обновляю свой Recyclerview
, но он никогда не показывается.Метод onDone()
Размер тоста result
, он не пустой.
Мой код:
class SearchFragment : Fragment() {
private lateinit var requestSearchPresenter: RequestSearchPresenter
private lateinit var recyclerViewAdapter: RecyclerViewAdapter
private var searchResult = ArrayList<ItemNewFeedCollection?>()
private val onRequestSearchResult = object : OnRequestSearchResult {
override fun onEmpty(result: ListNewFeedCollection) {
recyclerViewAdapter.notifyDataSetChanged()
}
override fun onDone(result: ListNewFeedCollection) {
searchResult = result.post
Toast.makeText(requireContext(), "${searchResult.size}", Toast.LENGTH_SHORT).show()
recyclerViewAdapter.notifyDataSetChanged()
}
override fun onFail(t: String) {
recyclerViewAdapter.notifyDataSetChanged()
}
}
private var recyclerViewItemClickListener = object : OnRecyclerViewItemClickListener {
override fun onItemClick(view: View, postion: Int) {
(requireActivity() as NewFeedActivity).apply {
val post = searchResult
if (post[postion]!!.date == "null" && post[postion]!!.date == post[postion]!!.description &&
post[postion]!!.date == post[postion]!!.full_post && post[postion]!!.date == post[postion]!!.image &&
post[postion]!!.date == post[postion]!!.full_post
) {
} else {
val link = post[postion]!!.link
val source = post[postion]!!.source
val intent = Intent(requireContext(), PostActivity::class.java)
intent.putExtra("link", link)
intent.putExtra("source", source)
startActivity(intent)
}
}
}
override fun onLongItemClick(view: View, postion: Int) {
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_search, container, false)
}
private fun configRecyclerView() {
recyclerViewAdapter = RecyclerViewAdapter(requireContext(), searchResult, recyclerViewItemClickListener)
recycler_view.layoutManager = LinearLayoutManager(requireContext())
recycler_view.adapter = recyclerViewAdapter
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
configRecyclerView()
val keyWord = arguments?.getString("key_word")
keyWord?.let {
requestSearchPresenter = RequestSearchPresenter(onRequestSearchResult)
requestSearchPresenter.search(it)
}
}
}
Но я перемещаю метод configRecyclerView()
в onDone()
, он отображается на:
override fun onDone(result: NewFeedCollection) {
searchResult = result.post
Toast.makeText(requireContext(), "${searchResult.size}", Toast.LENGTH_SHORT).show()
configRecyclerView()
recyclerViewAdapter.notifyDataSetChanged()
}