加载后逐一显示回收器视图项目而不是全部

Displaying recycler view items one by one instead of all after loading

我有一个包含多个对象和一个自定义适配器的列表。

ExampleAdapter adapter = new ExampleAdapter((ArrayList<MatchItem>) outputList, GamesActivity.this);
recyclerView.setAdapter(adapter);

问题是recycler 视图是在所有视图之后显示的,因为列表中的每个项目都完成了,但我想在加载每个项目后立即显示它。

我不确定是否必须创建适配器,因此它一次只接受一个项目作为参数,并在添加每个项目后更新数据。

我正在异步任务中填充列表并在 post 执行方法中设置适配器

不要将列表传递给适配器的构造函数,而是尝试在适配器中添加一个方法,该方法一次接受一个项目,然后在适配器中填充列表:

public class ExampleAdapter extends......{

private List< MatchItem > list = new ArrayList<MatchItem>();

public ExampleAdapter(GamesActivity.this){


}

//this method will accept items one by one
public void addNewItem(MatchItem item){

list.add(item);

this.notifyDataSetChanged();

}

}

并在物品准备好后开始一件一件地传递物品

//put these as a one time thing
ExampleAdapter adapter = new ExampleAdapter(GamesActivity.this);
recyclerView.setAdapter(adapter);

//when you read items
adapter.addNewItem(item);