Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView without xml definition

I want to create a dynamic number of ImageViews in Android. But to display these ImageViews I have to create them in the main.xml (Am I right?) Is there a way to display the ImageViews without creating them in the main.xml?

like image 347
hp58 Avatar asked Nov 04 '22 04:11

hp58


1 Answers

You can create them dynamically like this:

ImageView image=new ImageView(this);

and to set image in this dynamically created view use:

image.setImageResource(R.drawable.yourimage);
like image 119
Akram Avatar answered Nov 09 '22 11:11

Akram