1
私はここで間違っているのか分かりません。私はすべて同じ上記のアダプタを持っている別のフラグメントを取引しています、私の活動でアダプターが変更された後のバターナイフのレイアウトが読み込まれない
public class TestAdapter extends RecyclerView.Adapter<TestAdapter.ViewHolder> {
private final List<String> sourceData;
public TestAdapter(List<String> sourceData) {
this.sourceData = sourceData;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.spanitem_goods, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
String item = sourceData.get(position);
holder.textView.setText(item);
}
@Override
public int getItemCount() {
return sourceData.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.spanitem_imageView)
ImageView imageView;
@BindView(R.id.spanitem_textView)
TextView textView;
public ViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
}
}
}
どこか:
私のアダプタは、このようになります。これは、内と外にそれらを交換すると正常に動作しますが、できるだけ早く私は、アダプタ
adapter.notifyItemInserted(position);
上でこれを呼び出し、inとout再び断片をスワップとして、それはもはや任意のレイアウトをロードしません。ちょうど空白のページと私は上記のメソッドを呼び出すときに発生します。
私の抽象BaseFragment
このonCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG, "... onCreateView() called");
View v = inflater.inflate(getLayoutResourceId(), container, false);
unbinder = ButterKnife.bind(this, v);
ButterKnife.setDebug(true);
return v;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
Log.d(TAG, "... onDestroyView() called");
}
すべてのフラグメントが 'TestAdapter'の同じインスタンスを共有しているのですか?同じクラスの複数のインスタンスしか使用していませんか? – NitroNbg
@NitroNbg彼らはすべて自分のインスタンスを持っています –
ここでは、 'adapter.notifyItemInserted(position);'はここでは赤い鳴き声になる可能性がある(つまり、それは基本的なバグではない)と思います。 – NitroNbg