我已为RecyclerView
连接了适配器
那么,为什么我会不断收到此错误?
handler.post(new Runnable() {
@Override
public void run() {
progressBar.setVisibility(View.GONE);
imageAdapter = new ImageAdapter(getContext(),imageModelArrayList,ImageFragment.this);
recyclerView.setAdapter(imageAdapter);
imageAdapter.notifyDataSetChanged();
}
});
错误日志
E/RecyclerView: No adapter attached; skipping layout
E/RecyclerView: No adapter attached; skipping layout
答案 0 :(得分:0)
当您在创建阶段未设置适配器时发生,并且在您的情况下,是在延迟之后才进行设置的 因此,请尝试在您的onCreate方法中设置适配器,例如:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
imageAdapter = new ImageAdapter(getContext(),imageModelArrayList,ImageFragment.this);
recyclerView.setLayout(your layout);
recyclerView.setAdapter(imageAdapter);
}
但是如果是Fragment,则从ResultCallback方法内部调用代码会产生相同的消息。将代码移到我的应用程序中的onConnected()方法后,消息消失了……
或者您可以使用XML修复它,例如:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lastTransactionRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" // add this in
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnTransactionMenuBack"
tools:listitem="@layout/recycler_view_item_expense" />