2017-05-14 4 views
-2

ImageButton(メインアクティビティ)のイメージを他のアクティビティから変更しようとしています。
他のアクティビティは、ImageButtonが
を押したときにポップアップするダイアログなので、Canvasを使用しているユーザーから線を引いてサインを得ることができます。
ビットマップを取得しましたが、設定しようとするとクラッシュしました。
なぜこのようなことが起こるのか説明できる人はいますか?ImageViewの画像を他のアクティビティからどのように変更できますか?

final ImageButton imageButton = (ImageButton)findViewById(R.id.sign); 
//this 'sign' button is actually in Main Activity. not this class. Does this make problem? 

dv = new DrawingView(this); 

Button confirm = new Button(this); 
confirm.setText("confirm"); 
confirm.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     imageButton.setImageBitmap(dv.getBitmap()); 
     finish(); 
    } 
}); 

答えて

1

私はあなたがコードの問題は、アクティビティのオブジェクトにアクセスしようとしていることです。したがって、あなたは "NullPointerExcetion"に直面している必要があります。

((MainActivity) getActivity()).changeImage(bitmap); 

そして、あなたの "MainActivity" クラスでは、このような方法で作成します:

は、あなたの "DailogActivity" クラスでこれを試してみてください

public void changeImage(Bitmap bitmap){ 
    yourImageView.setBitmap(bitmap); 
} 
+0

感謝の私の多くを取ることを! – Yanguun

関連する問題