2017-07-09 22 views
-2

如何將圖像res發送到另一個活動 - 如何將資源更改爲整數? 我創建類圖片資源傳遞到另一個活動:發送圖像到另一個活動 - 如何將資源更改爲整數?

公共類MyImageView延伸的ImageView實現View.OnClickListener {

Context contxt; 


public MyImageView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    setOnClickListener(this); 
    this.contxt = context; 
} 


public MyImageView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    setOnClickListener(this); 
    this.contxt = context; 
} 


public MyImageView(Context context) { 
    super(context); 
    setOnClickListener(this); 
    this.contxt = context; 
} 


@Override 
public void setOnClickListener(OnClickListener l) { 

    super.setOnClickListener(l); 
} 


@Override 
public void onClick(View v) { 

    int g = getResourse......................;(this is my peroblem) 
    Bundle extras = new Bundle(); 
    extras.putInt("imagebitmap", g); 
    Intent i = new Intent(contxt, zara.knauf.Img.class); 
    i.putExtras(extras); 
    contxt.startActivity(i); 

} 
} 
+0

你拼寫錯誤RESOUR ** C ** E要RESOUR計劃** S **如我不知道它是否有幫助,但可能會在代碼中產生問題。無論如何,simlpy通過** id **並在被調用的活動中檢索資源** c ** e。 DONE。 –

+0

[這裏你可以找到你的答案。](https://stackoverflow.com/questions/11519691/passing-image-from-one-activity-another-activity)這已經解決了希望這會幫助你。 –

+0

@Ifran這不是傳遞資源ID –

回答

1

只需設置gR.drawable整數值。您無需致電getResources。您也不需要創建Bundle對象。

How to pass integer from one activity to another?

+0

對不起,我創建這個calss:(MyImageView擴展ImageView) –

+0

那麼......?這並不影響我的回答 –

相關問題