July 2015
Beginner to intermediate
600 pages
18h 59m
English
Throughout the book, you have been creating your views in layout files. It is also possible to create your views in code.
In fact, you could have defined your ViewPager in code without a layout file at all.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewPager viewPager = new ViewPager(this);
setContentView(viewPager);
...
}
No magic is necessary to create a view: just call its constructor, passing in a Context as the parameter. You can programmatically create an entire view hierarchy instead of using layout files.
However, creating views in code should be avoided, because layout files provide a few benefits.
One benefit of ...
Read now
Unlock full access