2017-12-27 149 views
-1

具有从活动发送图像的视图到另一个问题的布局,在我的应用我有活动登录,认证,当用户名是ABCD和密码是EFGH它会被重定向到这是玩家列表视图中的第二个活动,我想,当我点击一个玩家,我送他的名字和名字和他的形象,以聊天的活动,我将能够对准图像视图,姓和名的帽子活动的布局,在最后,我想创建一个对话框,为每个玩家,与他们沟通。发送图像视图从活动到另一个活动,并把它的第二个活动

的第一个问题是应用程序崩溃

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

      Intent i1 = new Intent(MainActivity.this,chatactivity.class); 
      Bundle b1 = new Bundle(); 
      b1.putString("prenom",joueurs.get(position).prenom); 
      b1.putString("nom",joueurs.get(position).nom); 
      b1.putInt("idimage",joueurs.get(position).imageid); 

      i1.putExtras(b1); 
      startActivity(i1); 
     } 
    }); 
+1

分享您的错误日志? – R2R

+0

你不能在各种活动中发送'ImageView'。你可以发送他们的资源ID,URI,文件路径,或者在最坏的情况下发送他们的位图字节到另一个活动。在第二个活动中,你应该有_another_' ImageView'应该显示相同的资源ID,URI,文件路径或位图。 –

回答

-1

用于发送:

Bitmap bitmap= ((BitmapDrawable)imageview.getDrawable()).getBitmap(); 
ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); 
byte[] b = baos.toByteArray(); 
Intent intent=new Intent(Passimage.this,myclass.class); 
intent.putExtra("picture", b); 
startActivity(intent); 

对于接收:

Bundle extras = getIntent().getExtras(); 
byte[] b = extras.getByteArray("picture"); 
Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length); 
ImageView image = (ImageView) findViewById(R.id.imageView1); 
image.setImageBitmap(bmp); 
+1

超过意图发送位图是不是一个好主意,它太大,可能会导致著名的TransactionTooLargeException – elmorabea

+0

我会尝试这个 –

+0

家伙我在的Android programmation初学者,如果你有另一种解决方案比这更好,更容易,请张贴! –

相关问题