Im trying to assign a picture in my .java file to one of my IDs开发者_如何学Python in the xml file. Can anyone show me some code that would help me with this? Thanks
Load the proper resource file using setContentView(R.layout.layout_of_activity)
Then, make an ImageView object and use the findViewById method by passing it the ID of the image that you assigned it from the xml file, i.e.
setContentView(R.layout.main);
ImageView picture = (ImageView) findViewById(R.id.pic_id);
Then you can do whatever you want with the pic like,
picture.setImageResource(R.drawable.picture_png);
Try checking out the android api samples to see how to do some more complex image manipulation like animating or rotating
精彩评论