我已经实现了Recycler View,但问题是它仅显示第一项。我通过的列表不是问题,因为它在logcat中显示了2个正确的项目。
Logcat:
D/TAGG LIST: [com.avalonglobalresearch.creatives.ImageUploadInfo@45bea08, com.avalonglobalresearch.creatives.ImageUploadInfo@6a145a1]
所以问题很可能是适配器造成的。 这是适配器代码:
public class RecyclerViewAdapter2 extends RecyclerView.Adapter<RecyclerViewAdapter2.ViewHolder> {
Context context2;
List<ImageUploadInfo> MainImageUploadInfoList;
public RecyclerViewAdapter2(Context context, List<ImageUploadInfo> TempList) {
this.MainImageUploadInfoList = TempList;
this.context2 = context;
}
@Override
public RecyclerViewAdapter2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items2, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public int getItemCount() {
return MainImageUploadInfoList.size();
}
@Override
public void onBindViewHolder(RecyclerViewAdapter2.ViewHolder holder, int position) {
ImageUploadInfo UploadInfo = MainImageUploadInfoList.get(position);
holder.imageNameTextView.setText(UploadInfo.getImageName());
Uri uri = Uri.parse(UploadInfo.getImageURL());
Log.d("TAGGG" , ""+uri);
//holder.videoView.setVideoURI(uri);
}
class ViewHolder extends RecyclerView.ViewHolder {
public VideoView videoView;
public TextView imageNameTextView;
public ViewHolder(View itemView) {
super(itemView);
videoView = (VideoView) itemView.findViewById(R.id.videoView2);
imageNameTextView = (TextView) itemView.findViewById(R.id.textView12);
}
}
}
这是我要向RecyclerView充气的类。
public class Photography extends AppCompatActivity {
private SlidrInterface slidr;
// Creating DatabaseReference.
DatabaseReference databaseReference;
// Creating RecyclerView.
RecyclerView recyclerView;
// Creating RecyclerView.Adapter.
RecyclerView.Adapter adapter ;
// Creating Progress dialog
ProgressDialog progressDialog;
// Creating List of ImageUploadInfo class.
List<ImageUploadInfo> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photography);
// Assign id to RecyclerView.
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
// Setting RecyclerView size true.
recyclerView.setHasFixedSize(true);
// Setting RecyclerView layout as LinearLayout.
recyclerView.setLayoutManager(new LinearLayoutManager(Photography.this));
// Assign activity this to progress dialog.
progressDialog = new ProgressDialog(Photography.this);
// Setting up message in Progress dialog.
progressDialog.setMessage("Loading Videos From Firebase.");
// Showing progress dialog.
progressDialog.show();
slidr = Slidr.attach(this);
// Setting up Firebase image upload folder path in databaseReference.
// The path is already defined in MainActivity.
databaseReference = FirebaseDatabase.getInstance().getReference("All_Uploads/Design/Videos/" );
// Adding Add Value Event Listener to databaseReference.
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
ImageUploadInfo imageUploadInfo = postSnapshot.getValue(ImageUploadInfo.class);
list.add(imageUploadInfo);
Log.d("TAGG LIST" , ""+list.toString());
}
adapter = new RecyclerViewAdapter2(getApplicationContext(), list);
recyclerView.setAdapter(adapter);
// Hiding the progress dialog.
progressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Hiding the progress dialog.
progressDialog.dismiss();
}
});
}
}
请告诉我我要去哪里哪里