2017-12-27 152 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初學者,如果你有另一種解決方案比這更好,更容易,請張貼! –

相關問題