2016-09-21 68 views
-3

我想传递的意图,从绘制图像,但没能做到如何从绘制通过图像意图

发件人活动:

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")); 
+0

请格式化您的代码! –

+0

你可以在意图发送位图,但不要这样做。你会遇到内存不足的错误。而是将图像保存到本地应用程序文件夹,并只发送意图图像的路径。 – HourGlass

回答

0

创建阵列

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

并通过它或只是通过

int drawable = R.drawable.image;