Update ListView in the main thread from another thread

前端 未结 6 793
北恋
北恋 2020-12-08 08:34

I have a separate thread running to get data from the internet. After that, I would like to update the ListView in the main thread by calling adapter.notifyDataSetChanged().

6条回答
  •  有刺的猬
    2020-12-08 09:03

    The trick here is the position where you put the

    mAdapter.notifyDataSetChanged();

    Here a simple example :

    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
    mAdapter = new myAdapter(......);
    mAdapter.notifyDataSetChanged();
    mRecyclerView.setAdapter(mAdapter);
    

    this work for me perfectly.

提交回复
热议问题