I have an Activity that has a main.xml with an ImageView. I then launch an other activity and wand to show the same picture that is in the first activity. My second activity's layout is created programmatically with linearlayout (ll). I then use the following:
ImageView img = (ImageView) findViewById(R.drawable.logo);
ll.addView(img);
setContentView(ll);
but i get img to be null, It doesnt work if i change it to R.id.logo which is defined at main.xml
First create a new imageview by doing ImageView img = new ImageView(this);
Then set your drawable to any image you have in your "drawable" folders for example: img.setImageResource(R.drawable.my_image);
Then you can add it to your linear layout like you do above and then setContentView.
What you were doing above to findViewById does not make sense because you did not set content view. So just follow the setups i outlined above.