RecyclerView: No adapter attached; a solution to the skipping layout problem

Problem statement:

RecyclerView is often used for layout in development, and then when the interface is started, because there is a delay in obtaining data from databases or networks, etc., when the data is not obtained and RcyclerView is loaded, RecyclerView: No adapter attached will appear; The skipping layout causes the APP to crash for no reason.

Solution:

First hide the layout setVisibility(View.GONE) of RecyclerView, optimize some and add a loading screen, and then hide the layout setVisibility(View.VISIBLE) of RecyclerView after the data is loaded, and hide the loading screen.
The following is a simple display in pseudocode:

	onCrete{
    
    
		pbLoading.setVisibility(View.VISIBLE);
		RecyclerView.setVisibility(View.GONE);
		
		监听数据加载完成后
		
		pbLoading.setVisibility(View.GONE);
		LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity);
        RecyclerView.setLayoutManager(linearLayoutManager);
        RecyclerViewAdapter = new RecyclerViewAdapter(this,数据);
		RecyclerView.setVisibility(View.VISIBLE);
		RecyclerView.setAdapter(calendarAdapter);
	}

Guess you like

Origin blog.csdn.net/shendaoyu/article/details/121679574