Sujay Kumar
Sujay Kumar

Reputation: 558

Android: Is it better to declare ImageView or Buttons programatically or i can just use it from the XML file?

I am finalizing my chess project and I have done all the things dynamically in the code, like this:

two_player = new ImageView(ctx);
two_player.setImageResource(R.drawable.twoplayers);

I know I can also do it in the xml file and just find it like this:

ImageView twoplayer = (ImageView) findViewById(R.id.twoplayer);

I am confused which one is faster: dynamically defining or the xml file calling?

Upvotes: 1

Views: 288

Answers (1)

pskink
pskink

Reputation: 24720

of course inflating from xml is slower in run-time but much faster in code-writing-time ;)

Upvotes: 1

Related Questions