使用 VOLLEY 将 onclickListener 放入 RecyclerViewAdapter 时,图像未显示在新 Activity 中

Image is not displaying in new Activity while putting onclickListener in RecyclerViewAdapter using VOLLEY

图像未在新版中显示 activity...我将 OnclickListener 放在 RecyclerViewAdaptor 上...我正在使用 Volley...我想在新版中同时显示图像和文本 activity ..但只显示文字!!..任何人都可以帮助我吗?

我认为问题出在意图部分....但我不明白为什么图像没有显示

MyAdaptor.java

package com.example.volleydemo;


import android.content.Context;
import android.content.Intent;
import android.service.autofill.UserData;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

public class MyAdaptor extends RecyclerView.Adapter<MyAdaptor.myviewholder>
{
    DisplayUser data[];

    Context context;

    public MyAdaptor(DisplayUser[] data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public myviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //create layout like custom_link.xml
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_list_item,parent,false);
        return new myviewholder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull myviewholder holder, int position)
    {

        holder.t1.setText(data[position].getName());
        holder.t2.setText(data[position].getDesig());
        Glide.with(holder.t1.getContext()).load("http://10.0.2.2/volley/images/"+data[position].getImage()).into(holder.img);

        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //Toast.makeText(context,"image : "+holder.img,Toast.LENGTH_LONG).show();

               Intent intent = new Intent(context,DetailsActivity.class);
               intent.putExtra("imagename",data[position].getImage());
               intent.putExtra("header",data[position].getName());
               intent.putExtra("desc",data[position].getDesig());
               intent.putExtra("rollno",data[position].getRollno());

               intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
               context.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        return data.length;
    }

    class myviewholder extends RecyclerView.ViewHolder
  {
      ImageView img;
      TextView t1,t2;

      public myviewholder(@NonNull View itemView) {
          super(itemView);

          img = itemView.findViewById(R.id.img);
          t1 = itemView.findViewById(R.id.t1);
          t2 = itemView.findViewById(R.id.t2);

      }
  }
}

这是新的活动文件 DetailsActivity.java

package com.example.volleydemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

public class DetailsActivity extends AppCompatActivity {

    ImageView img;
    TextView tv1,tv2;

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

        img = findViewById(R.id.desc_img);
        tv1 = findViewById(R.id.desc_header);
        tv2 = findViewById(R.id.desc_desc);

        img.setImageResource(getIntent().getIntExtra("imagename",0));
        //Glide.with(holder.t1.getContext()).load("http://10.0.2.2/volley/images/"+data[position].getImage()).into(holder.img);

        tv1.setText(getIntent().getStringExtra("header"));
        tv2.setText(getIntent().getStringExtra("desc"));
    }
}

这是持有人class.. DisplayUser.java

package com.example.volleydemo;

public class DisplayUser {
    //this is helper class

    private String rollno,name,desig,image;

    public DisplayUser() {

    }

    public DisplayUser(String rollno, String name, String desig, String image) {
        this.rollno = rollno;
        this.name = name;
        this.desig = desig;
        this.image = image;
    }

    public String getRollno() {
        return rollno;
    }

    public void setRollno(String rollno) {
        this.rollno = rollno;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesig() {
        return desig;
    }

    public void setDesig(String desig) {
        this.desig = desig;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }
}

在你的 DetailsActivity,

替换:

  img.setImageResource(getIntent().getIntExtra("imagename",0));
  Glide.with(holder.t1.getContext()).load("http://10.0.2.2/volley/images/"+data[position].getImage()).into(holder.img);

收件人:

 Glide.with(getApplicationContext()).load("http://10.0.2.2/volley/images/"+getIntent().getStringExtra("imagename").into(img);