我保存了数据,即物品详细信息以及用于出售它们的图像。现在,我正尝试将这些详细信息与图像一起显示以进行出售,但很遗憾,没有显示任何内容。
我正在使用回收站视图和图像适配器来显示我的数据。
这是我检索数据的方式:-----
public class books extends AppCompatActivity {
private RecyclerView mRecyclerView;
private ImageAdapter mAdapter;
private ProgressBar mProgressCircle;
DatabaseReference mDatabaseRef;
private List<post> mPosts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_books);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mProgressCircle = findViewById(R.id.progress_circle);
mPosts = new ArrayList<>();
mDatabaseRef = FirebaseDatabase.getInstance().getReference("Items");
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
post Post = postSnapshot.getValue(post.class);
mPosts.add(Post);
}
mAdapter = new ImageAdapter(books.this, mPosts);
mRecyclerView.setAdapter(mAdapter);
mProgressCircle.setVisibility(View.INVISIBLE);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(books.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
mProgressCircle.setVisibility(View.INVISIBLE);
}
});
}}
这是我的上课时间:----
public class post {
private String category;
private String itemnames;
private String desc;
private String cost;
private String contact;
private String imageurl;
public post() {
}
public post(String category_val, String itemname_val, String desc_val, String cost_val, String contact_val, String imageurl_val) {
if (category_val.trim().equals("") && itemname_val.trim().equals("") && desc_val.trim().equals("") && cost_val.trim().equals("") && contact_val.trim().equals("") ) {
category_val="No Category";
itemname_val = "No Name";
desc_val="No Desc";
cost_val = "No Cost";
contact_val="No Contact";
}
category = category_val;
itemnames = itemname_val;
desc = desc_val;
cost = cost_val;
contact = contact_val;
imageurl = imageurl_val;
}
public String getCategory() {
return category;
}
public void setCategory(String category_val) {
category = category_val;
}
public String getitemname() {
return itemnames;
}
public void setitemname(String itemname_val) {
itemnames = itemname_val;
}
public String getdesc() {
return desc;
}
public void setdesc(String desc_val) {
desc = desc_val;
}
public String getcost() {
return cost; }
public void setcost(String cost_val) {
cost = cost_val;
}
public String getcontact() {
return contact;
}
public void setcontact(String contact_val) {
contact = contact_val;
}
public String getimageurl() {
return imageurl; }
public void setimageurl(String imageurl_val) {
imageurl = imageurl_val;
}}
这是我的图像适配器类:-----
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private Context mContext;
private List<post> mPosts;
ImageAdapter(Context context, List<post> posts) {
mContext = context;
mPosts = posts;
}
@Override
public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.image_item, parent, false);
return new ImageViewHolder(v);
}
@Override
public void onBindViewHolder(ImageViewHolder holder, int position) {
post postCurrent = mPosts.get(position);
holder.textViewCategory.setText(postCurrent.getCategory());
holder.textViewName.setText(postCurrent.getitemname());
holder.textViewDesc.setText(postCurrent.getdesc());
holder.textViewCost.setText(postCurrent.getcost());
holder.textViewContact.setText(postCurrent.getcontact());
Picasso.with(mContext)
.load(postCurrent.getimageurl())
.fit()
.centerInside()
.into(holder.imageView);
}
@Override
public int getItemCount() {
return mPosts.size();
}
public class ImageViewHolder extends RecyclerView.ViewHolder {
TextView textViewName;
TextView textViewCategory;
TextView textViewDesc;
TextView textViewCost;
TextView textViewContact;
ImageView imageView;
ImageViewHolder(View itemView) {
super(itemView);
textViewCategory = itemView.findViewById(R.id.text_view_name_1);
textViewName = itemView.findViewById(R.id.text_view_name_2);
textViewDesc = itemView.findViewById(R.id.text_view_name_3);
textViewCost = itemView.findViewById(R.id.text_view_name_4);
textViewContact = itemView.findViewById(R.id.text_view_name_5);
imageView = itemView.findViewById(R.id.image_view_upload);
}
}}
我希望输出与图像一起显示为数据,但仅显示卡而不显示数据和图像。