I'm pretty new to android development and my newest project requires
me to change the source of an imageview from within my code. I'm just
trying to test this out right now and I'm running into problems. If I
create my layout from within code ("The commented code below"), my app
runs and successfully displays my image, but I would rather design my
UI in an xml and just change the image source for the specific
imageview. When I define the image source in my xml, my app runs
successfully. I run into my problem when I try to set the image source
from within code by retrieving the imageview by id. I get no error,
but when the app attempts to launch, I get an error stating that the
app stopped unexpectedly. I have tried "cleaning" my project with
eclipse, but that fixes nothing. My code is below:
extends Activity {
LinearLayout mLinearLayout;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView i = (ImageView)
findViewById(R.id.imageView_AminoAcid);
i.setImageResource(R.drawable.wierdsmiley);
setContentView(R.layout.main);
/*mLinearLayout = new LinearLayout(this);
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.wierdsmiley);
i.setAdjustViewBounds(true);
i.setLayoutParams(new
Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mLinearLayout.addView(i);
setContentView(mLinearLayout);*/
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en