For some unknown reason, I can't add an item to RecyclerView.
I have an onActivityResult method and in it I do the following things:
file.add(new FileModel()); In turn, somewhere higher in the OnStart method:
file = new ArrayList<>(); fAdapter = new ADDFileAdapter(file); rvAddFile.setAdapter(fAdapter); If I fill in the file in the OnStart method, the elements are added and displayed.
rvAddFile.setAdapter(fAdapter); file.add(new FileModel()); file.add(new FileModel()); file.add(new FileModel()); The question is why in the onActivityResul t method the elements are not added to RecyclerView?
UPD
public class ADDFileAdapter extends RecyclerView.Adapter<ADDFileAdapter.ADDFileViewHolder> { ArrayList<FileModel> fileConteiner; public ADDFileAdapter(ArrayList<FileModel> fileConteiner) { this.fileConteiner = fileConteiner; } @Override public ADDFileViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.add_file_card_layout, parent, false); ADDFileAdapter.ADDFileViewHolder nh = new ADDFileAdapter.ADDFileViewHolder(v); return nh; } @Override public void onBindViewHolder(ADDFileViewHolder holder, int position) { Context ctx = holder.itemView.getContext(); LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams lparamsFile = new LinearLayout.LayoutParams(100,100); LinearLayout linearLayoutFileContent = new LinearLayout(ctx); //Контейнер для вложения linearLayoutFileContent.setLayoutParams(lparams); for (int i = 0; i < fileConteiner.size(); i++){ ImageView file = new ImageView(ctx); //Изображение вложения file.setLayoutParams(lparamsFile); file.setImageDrawable(ctx.getResources().getDrawable(R.drawable.audio)); linearLayoutFileContent.addView(file); } holder.cv.addView(linearLayoutFileContent); } @Override public int getItemCount() { return fileConteiner.size(); } public static class ADDFileViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ CardView cv; public ADDFileViewHolder(View itemView) { super(itemView); cv = (CardView) itemView.findViewById(R.id.add_file_card); } @Override public void onClick(View view) { } } onActivityResult method
if(u.toString().equals("image/jpeg") || u.toString().equals("image/png") || u.toString().equals("image/gif") || u.toString().equals("image/tiff")){ fileAdd.add(new FileModel()); fAdapter.notifyDataSetChanged(); } Debugger
