我无法从Firebase将数据(图像,文本,视频)全部下载到具有多种视图类型的一个回收视图中。屏幕只是空白。
这是我要显示数据的班级
public class Literature extends AppCompatActivity {
private SlidrInterface slidr;
StorageReference storageRef;
String Storage_Path = "All_Uploads/";
// Creating DatabaseReference.
DatabaseReference databaseReference;
// Creating RecyclerView.
RecyclerView recyclerView;
// Creating RecyclerView.Adapter.
RecyclerView.Adapter adapter ;
// Creating Progress dialog
ProgressDialog progressDialog;
// Creating List of ImageUploadInfo class.
ArrayList<Model> list= new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_literature);
storageRef = FirebaseStorage.getInstance().getReference();
slidr = Slidr.attach(this);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(Literature.this));
progressDialog = new ProgressDialog(Literature.this);
progressDialog.setMessage("Loading Images From Firebase.");
progressDialog.show();
databaseReference = FirebaseDatabase.getInstance().getReference("All_Uploads/Design/" );
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Model model = postSnapshot.getValue(Model.class);
list.add(model);
}
adapter = new MultiViewTypeAdapter(list , getApplicationContext());
recyclerView.setAdapter(adapter);
// Hiding the progress dialog.
progressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Hiding the progress dialog.
progressDialog.dismiss();
}
});
}
}
这是Recycler View的适配器类
public class MultiViewTypeAdapter extends RecyclerView.Adapter {
private ArrayList<Model>dataSet;
Context mContext;
int total_types;
MediaPlayer mPlayer;
private boolean fabStateVolume = false;
public static class TextTypeViewHolder extends RecyclerView.ViewHolder {
TextView txtType;
CardView cardView;
public TextTypeViewHolder(View itemView) {
super(itemView);
this.txtType = (TextView) itemView.findViewById(R.id.type);
this.cardView = (CardView) itemView.findViewById(R.id.card_view);
}
}
public static class ImageTypeViewHolder extends RecyclerView.ViewHolder {
TextView txtType;
ImageView image;
public ImageTypeViewHolder(View itemView) {
super(itemView);
this.txtType = (TextView) itemView.findViewById(R.id.type);
this.image = (ImageView) itemView.findViewById(R.id.background);
}
}
public static class VideoTypeViewHolder extends RecyclerView.ViewHolder {
TextView txtType;
FloatingActionButton fab;
public VideoTypeViewHolder(View itemView) {
super(itemView);
this.txtType = (TextView) itemView.findViewById(R.id.type);
this.fab = (FloatingActionButton) itemView.findViewById(R.id.fab);
}
}
public MultiViewTypeAdapter(ArrayList<Model>data, Context context) {
this.dataSet = data;
this.mContext = context;
total_types = dataSet.size();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch (viewType) {
case Model.TEXT_TYPE:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.text_type, parent, false);
return new TextTypeViewHolder(view);
case Model.IMAGE_TYPE:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_type, parent, false);
return new ImageTypeViewHolder(view);
case Model.VIDEO_TYPE:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_type, parent, false);
return new VideoTypeViewHolder(view);
}
return null;
}
@Override
public int getItemViewType(int position) {
switch (dataSet.get(position).type) {
case 0:
return Model.TEXT_TYPE;
case 1:
return Model.IMAGE_TYPE;
case 2:
return Model.VIDEO_TYPE;
default:
return -1;
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int listPosition) {
Model object = dataSet.get(listPosition);
if (object != null) {
switch (object.type) {
case Model.TEXT_TYPE:
((TextTypeViewHolder) holder).txtType.setText(object.text);
break;
case Model.IMAGE_TYPE:
((ImageTypeViewHolder) holder).txtType.setText(object.text);
((ImageTypeViewHolder) holder).image.setImageResource(object.data);
break;
case Model.VIDEO_TYPE:
break;
}
}
}
@Override
public int getItemCount() {
return dataSet.size();
}
}
这是Model类
public class Model {
public static final int TEXT_TYPE=0;
public static final int IMAGE_TYPE=1;
public static final int VIDEO_TYPE=2;
public int type;
public int data;
public String text;
public Model(int type, String text, int data)
{
this.type=type;
this.data=data;
this.text=text;
}
}
请帮助我看看我要去哪里