如何从drawable中传递图像

时间:2016-09-21 05:59:40

标签: java android android-intent android-drawable

我试图从drawable中传递图像但无法做到

发件人活动:

public class ShowSquadAdapter extends RecyclerView.Adapter<ShowSquadAdapter.ViewHolder> {

    Context con;
    Bitmap bmp,bmp1,bmp2,bmp3,bmp4,bmp5,bmp6,bmp7,bmp8,bmp9,bmp10,bmp11,bmp12,bmp13,bmp14,bmp15;
    public ArrayList<SquadModel> squad=new ArrayList<SquadModel>();

    public ShowSquadAdapter(Context con,ArrayList<SquadModel> data)
    {
        this.con=con;
        this.squad=data;

    }
    @Override
    public ShowSquadAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(con).inflate(R.layout.card_squad,parent,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ShowSquadAdapter.ViewHolder holder, int position) {

        final SquadModel squadModel = squad.get(position);
        if(holder==null) {
            Log.e("tag","null");
        }

        ImageView imageView=holder.imvplayer;
      imageView.setImageResource(squadModel.getIconid());
        if(holder.equals(null))
        {
            Log.e("tag","null");
        }
        TextView textView = holder.tvplayername;
        textView.setText(squadModel.getName());
        holder.linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 Intent j = new Intent(con,ShowSquad.class);
j.putExtra("Juan Calatayud",squadModel.getIconid());
                Log.e("tag", String.valueOf(squadModel.getIconid()));
                j.putExtra("Amrinder Singh",squadModel.getIconid());
                j.putExtra("Kunzang Bhutia",squadModel.getIconid());
                j.putExtra("Nallappan Mohanraj",squadModel.getIconid());
                j.putExtra("Arnab Mondal",squadModel.getIconid());
                j.putExtra("Denzil Franco",squadModel.getIconid());
                j.putExtra("Syed Rahim Nabi",squadModel.getIconid());
                j.putExtra("Rino Anto",squadModel.getIconid());
                j.putExtra("Augustin Fernandes",squadModel.getIconid());
                j.putExtra("Jaime Gavilán",squadModel.getIconid());
                j.putExtra("Borja Fernández",squadModel.getIconid());
                j.putExtra("Clifford Miranda",squadModel.getIconid());
                j.putExtra("Arata Izumi",squadModel.getIconid());
                j.putExtra("Sameehg Doutie",squadModel.getIconid());
                j.putExtra("Ofentse Nato",squadModel.getIconid());
                j.putExtra("Jorge Alonso",squadModel.getIconid());

接收者活动:

public class ShowSquad extends AppCompatActivity {
    public ArrayList<SquadModel> squad=new ArrayList<SquadModel>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        ImageView imageView;
        TextView textView;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_showsquad);
        imageView=(ImageView)findViewById(R.id.imvshowsquad);
        textView=(TextView)findViewById(R.id.tvshow);
        Bundle bundle = getIntent().getExtras();
        //SquadModel squadModel = squad.
        if(bundle!=null) {

            byte arr[] = getIntent().getByteArrayExtra("Juan Calatayud");
            Bitmap bmp = BitmapFactory.decodeByteArray(arr,0,arr.length);
            imageView.setImageBitmap(bmp);
                //SquadModel squadModel = squad.get(i);
                imageView.setImageResource(bundle.getInt("Juan Calatayud",R.drawable.p_juan));
                imageView.setImageResource(bundle.getInt("Amrinder Singh"));
                imageView.setImageResource(bundle.getInt("Kunzang Bhutia"));
                imageView.setImageResource(bundle.getInt("Nallappan Mohanraj"));
                imageView.setImageResource(bundle.getInt("Arnab Mondal"));
                imageView.setImageResource(bundle.getInt("Denzil Franco"));
                imageView.setImageResource(bundle.getInt("Syed Rahim Nabi"));
                imageView.setImageResource(bundle.getInt("Rino Anto"));
                imageView.setImageResource(bundle.getInt("Augustin Fernandes"));
                imageView.setImageResource(bundle.getInt("Jaime Gavilán"));
                imageView.setImageResource(bundle.getInt("Borja Fernández"));
                imageView.setImageResource(bundle.getInt("Clifford Miranda"));
                imageView.setImageResource(bundle.getInt("Arata Izumi"));
                imageView.setImageResource(bundle.getInt("Sameehg Doutie"));
                imageView.setImageResource(bundle.getInt("Ofentse Nato"));
                imageView.setImageResource(bundle.getInt("Jorge Alonso"));

1 个答案:

答案 0 :(得分:0)

创建

数组
int[] drawables = {R.drawables.image,R.drawables.image2,R.drawables.image3}; 

传递或传递

int drawable  = R.drawable.image;