我正在尝试将用户帖子从适配器发送到另一个活动。这是我如何做到的:
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
final Post post= mPost.get(position);
Glide.with(mContext).load(post.getPostimage())
.apply(new RequestOptions().placeholder(R.drawable.loading_image))
.into(holder.post_image);
holder.post_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mContext, PostDetails.class);
i.putExtra("postimage",post.getPostimage());
mContext.startActivity(i);
((Activity) mContext).overridePendingTransition(0, 0);
}
});
}
Run Code Online (Sandbox Code Playgroud)
在其他活动中:
postImage = findViewById(R.id.postImage);
postImage.setImageResource(getIntent().getIntExtra("postimage", 0));
Run Code Online (Sandbox Code Playgroud)
这是后模型类:
public class Post {
private String postid;
private String postimage;
private String title;
private String publisher;
public Post(String postid, String postimage, String title, String publisher)
{
this.postid = …
Run Code Online (Sandbox Code Playgroud) android ×1