简体   繁体   English

如何在 Recyclerview 项目单击方法中将图像获取到新活动

[英]How to Get image to new Activity in Recyclerview item click method

I am creating an News feed like Activity in which image is retrieved from firebase to Recyclerview and displayed using picasso.我正在创建一个像 Activity 这样的新闻提要,其中图像从 firebase 检索到 Recyclerview 并使用 picasso 显示。 I need to open same details in new Activity by Onclick.我需要在 Onclick 的新活动中打开相同的详细信息。 i am getting text message in new Acvtivity.我在新的 Acvtivity 中收到短信。 But how can i get the image there using url.但是我怎样才能使用 url 在那里获得图像。 kindly help for coding.请帮助编码。

My main Adapter我的主适配器

public class NoticeAdapter extends RecyclerView.Adapter<NoticeAdapter.Noticeviewholder> {
    public List<Noticemodel> noticemodelList;
    Notice notice;


    public NoticeAdapter(List<Noticemodel> noticemodelList, Notice notice) {
        this.noticemodelList = noticemodelList;
        this.notice=notice;
    }



    @NonNull
    @Override
    public Noticeviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater=LayoutInflater.from(parent.getContext());
        View view=layoutInflater.inflate(R.layout.notice_item,null,false);
        return new Noticeviewholder(view,notice,noticemodelList);
    }

    @Override
    public void onBindViewHolder(@NonNull final Noticeviewholder noticeviewholder, final int position) {
        noticeviewholder.ntitle.setText(noticemodelList.get(position).getTitle());
        noticeviewholder.ndescription.setText(noticemodelList.get(position).getDescription());
        Picasso.get().load(noticemodelList.get(position).getImage()).into(noticeviewholder.nimageview);

    }

    @Override
    public int getItemCount() {
        return noticemodelList.size();
    }

    public class Noticeviewholder extends RecyclerView.ViewHolder implements View.OnClickListener
    {
        TextView ntitle;
        TextView ndescription;
        ImageView nimageview;
        Notice notice;
        List<Noticemodel> noticemodelList;
        public Noticeviewholder(View itemView, Notice notice, List<Noticemodel> noticemodelList) {
            super(itemView);
            this.notice=notice;
            this.noticemodelList=noticemodelList;
            itemView.setOnClickListener(this);
            ntitle=itemView.findViewById(R.id.notTitle);
            ndescription=itemView.findViewById(R.id.notDescription);
            nimageview=itemView.findViewById(R.id.notImage);

        }


        @Override
        public void onClick(View view) {
            int position = getAdapterPosition();
            Noticemodel noticemodel=this.noticemodelList.get(position);
            Intent intent= new Intent(this.notice,Noticedetails.class);
            intent.putExtra("title",noticemodelList.get(position).getTitle());
            intent.putExtra("description",noticemodelList.get(position).getDescription());
            intent.putExtra("image",noticemodelList.get(position).getImage());
            this.notice.startActivity(intent);

        }
    }
}

New activity class新活动class

public class Noticedetails extends AppCompatActivity {
    TextView ndTiltle,ndDescription;
    ImageView ndImage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_noticedetails);

        ndTiltle= findViewById(R.id.ndTitle);
        ndDescription= findViewById(R.id.ndDescription);
        ndImage= findViewById(R.id.ndImage);

        ndImage.setImageResource(getIntent().getIntExtra("image",00));
        ndTiltle.setText(getIntent().getStringExtra("title"));
        ndDescription.setText(getIntent().getStringExtra("description"));

    }
}

In New activity set image using Picasso在使用Picasso的新活动集图像中

Picasso.get().load(getIntent().getStringExtra(“image”)).into(ndImage);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在RecyclerView中使用不同的数据和照片在项目单击上打开新的活动 - How to open new Activity on item click with different data and photo in RecyclerView 单击 RecyclerView 时如何移动到新活动 - How to move to new activity when click RecyclerView 单击RecyclerView中包含在片段中的项目以打开带有传递数据的新活动 - Click On An Item In RecyclerView Contained In A Fragment To Open New Activity With Passed Data 在项目上单击Recyclerview将图像设置为活动中的另一个imageview - Recyclerview on item click set image to another imageview in activity 如何在活动的recyclerview中获取项目的位置 - How to get a position of item in recyclerview to a activity 点击recyclerView new activity Error Attempt to invoke virtual method - Click recyclerView new activity Error Attempt to invoke virtual method 如何在Android中的recyclerview项目点击事件中从适配器获取活动的价值? - How to get value from adapter to activity on recyclerview item click event in Android? 单击按钮即可新建RecyclerView项目 - New RecyclerView item on click of button 如何单击 RecyclerView 项目以转到详细活动并在我单击的 RecyclerView 中应用项目的标题和价格? - How can I click on a RecyclerView item to go to detailed activity and apply the title and price of the item in the RecyclerView that I clicked? 如何根据RecyclerView中的单击项在新活动中打开特定片段 - How to open specific Fragment in new Activity depending on clicked item in RecyclerView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM