How can I find an object (for example Imageview) in the Mainactivity from another class that this class have extends?
my Mainactivity :
public class MainActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onClick(View view){
}}
my DrawingView class:
public class DrawingView extends View {
public DrawingView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
drawCanvas = new Canvas(canvasBitmap);
}
............
}
in my activity_main.xml I have an Imageview, but i cant find it. I searched in site and best answer is like this:
How to update a TextView of an activity from another class
but this answer dose not help me. how can I find Imageview in onTouchEvent or others part of DrawingView class? and why this cod dos not work for me:
imageView = (ImageView) getRootView().findViewById(R.id.imageView);