我正在尝试使用回收站视图创建底部片断。但是我在回收站视图中遇到错误adapter not set skipping layout
我很肯定我为回收站视图设置了适配器。我似乎不明白这个问题。
底片片段代码
public class QueueBottomSheetDialog extends BottomSheetDialogFragment {
//Views
private View fragmentView;
private RecyclerView queueRecyclerView;
private QueueRecyclerAdapter queueRecyclerAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
fragmentView = inflater.inflate(R.layout.queue_bottomsheet,container,false);
Initialize();
populateSongs();
return fragmentView;
}
private void Initialize(){
queueRecyclerView = fragmentView.findViewById(R.id.queue_recyclerView);
queueRecyclerView.setHasFixedSize(true);
}
private void populateSongs(){
queueRecyclerAdapter = new QueueRecyclerAdapter(getContext(),MusicService.songsSet);
queueRecyclerView.setAdapter(queueRecyclerAdapter);
queueRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
}
回收适配器代码
public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdapter.QueueViewHolder> {
private Context context;
private SongSet songSet;
public QueueRecyclerAdapter(Context context,SongSet songSet){
this.context = context;
this.songSet = songSet;
}
@NonNull
@Override
public QueueViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.queue_cardview,parent,false);
return new QueueViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull QueueViewHolder holder, int position) {
holder.songTv.setText(songSet.get(position).getTitle());
holder.artistTv.setText(songSet.get(position).getArtist());
}
@Override
public int getItemCount() {
return songSet.size();
}
public static class QueueViewHolder extends RecyclerView.ViewHolder{
private TextView songTv;
private TextView artistTv;
public QueueViewHolder(@NonNull View itemView) {
super(itemView);
songTv = itemView.findViewById(R.id.sName);
artistTv = itemView.findViewById(R.id.aName);
}
}
}
我在我的主要活动中这样打电话
queueBottomSheetDialog queueBottomSheetDialog = newQueueBottomSheetDialog();
queueBottomSheetDialog.show(getSupportFragmentManager(),"QUEUE BOTTOMSHEET");