Я использую студию android для создания приложения. Так как я новичок в android разработке студии, не могу понять проблему. Мое приложение работает правильно. но вид карты не виден в окне просмотра. пожалуйста, помогите мне. это мой вид карты адаптера переработчика
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
private Context mContext;
private List<Upload> uploads;
public RecyclerViewAdapter(Context mContext, List<Upload> uploads) {
this.mContext = mContext;
this.uploads = uploads;
}
public RecyclerViewAdapter(Context mContext) {
this.mContext = mContext;
}
public void setList(List<Upload> uploads) {
this.uploads = uploads;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
LayoutInflater inflater = LayoutInflater.from(mContext);
view = inflater.inflate(R.layout.card_view_item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
final Upload upload = uploads.get(position);
holder.tv_book_title.setText(upload.getName());
Glide.with(mContext).load(upload.getUrl()).into(holder.imd_book_thumbnail);
}
@Override
public int getItemCount() {
return uploads == null ? 0 : uploads.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView tv_book_title;
ImageView imd_book_thumbnail;
CardView cardView;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
tv_book_title = itemView.findViewById(R.id.book_title_id);
imd_book_thumbnail = itemView.findViewById(R.id.book_img_id);
cardView = itemView.findViewById(R.id.card_view_id);
}
}
}
и это мой вид карты XML код файла
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:id="@+id/card_view_id"
android:layout_width="120dp"
android:layout_height="190dp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_margin="5dp"
app:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="160dp"
android:id="@+id/book_img_id"
android:scaleType="centerCrop"
android:padding="2dp"
android:background="#2d2">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#2d2d2d"
android:id="@+id/book_title_id"
android:text="@string/title"
android:textSize="13sp"
android:layout_gravity="center" >
</TextView>
</LinearLayout>
моя основная деятельность - следовать
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recyclerview_id);
recyclerView.setLayoutManager(new GridLayoutManager(this,3));
adapter = new RecyclerViewAdapter(getApplicationContext());
recyclerView.setAdapter(adapter);
progressDialog = new ProgressDialog(this);
uploads = new ArrayList<>();
progressDialog.setMessage("Please wait ...");
progressDialog.show();
mDatabase = FirebaseDatabase.getInstance().getReference("upload");
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
progressDialog.dismiss();
for (DataSnapshot postsnapshot : dataSnapshot.getChildren())
{
Upload upload= postsnapshot.getValue(Upload.class);
uploads.add(upload);
}
adapter.setList(uploads);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
progressDialog.dismiss();
}
});
}