我正在尝试以AlertDialog
方法显示onActivityResult
上的文件数据列表。 AlertDialog
弹出,但recyclerView
仅在空白对话框中不可见。我检查了适配器的ItemCount,它显示的列表大小很好。
活动中的onActivityResult方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Uri uri;
String type;
View dialogView;
RecyclerView dialogRecyclerview;
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
ContentResolver cr = this.getContentResolver();
if(requestCode==1 && resultCode==RESULT_OK){
dialogView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.alertdialog_files,null);
dialogRecyclerview = dialogView.findViewById(R.id.alertdialog_fiilerecyclerView);
dialogBuilder.setView(dialogView);
dialogRecyclerview.setHasFixedSize(true);
dialogRecyclerview.setLayoutManager(new LinearLayoutManager(this));
dialogBuilder.setCancelable(true);
uploadChatFileAdapter = new UploadChatFileAdapter(uploadFileList);
if(data.getClipData()!=null){
int totalItems = data.getClipData().getItemCount();
for(int i = 0 ; i < totalItems ; i++){
uri = data.getClipData().getItemAt(i).getUri();
type = cr.getType(uri);
uploadFileList.add(type);
uploadChatFileAdapter.notifyDataSetChanged();
}
}else if(data.getData()!=null) {
uri = data.getData();
type = cr.getType(uri);
uploadFileList.add(type);
uploadChatFileAdapter.notifyDataSetChanged();
}
dialogRecyclerview.setAdapter(uploadChatFileAdapter);
dialogBuilder.show();
}
}
适配器类
UploadChatFileAdapter(List<String> uploadList) {
this.uploadList = uploadList;
}
@NonNull
@Override
public FileUploadViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.set_meeting_userlist_item,parent,false);
return new FileUploadViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull FileUploadViewHolder holder, int position) {
holder.txt.setText(uploadList.get(position));
}
@Override
public int getItemCount() {
return uploadList.size();
}
class FileUploadViewHolder extends RecyclerView.ViewHolder{
TextView txt;
FileUploadViewHolder(View itemView) {
super(itemView);
txt = itemView.findViewById(R.id.set_meeting_userlist_txtview);
}
}