You typically use Java code to generate the layout if you do not know the content until runtime; e.g., if your layout depends on content which you read from the Internet. An example of this is the next three statements whose screenshot is on the right: |
TextView tv = new TextView( this ); tv.setText( "Hello, Android" ); setContentView( tv );which compose the string “Hello, Android” and display it.
/res/layout
.res/layout/activity_main.xml
and
res/layout/activity_next.xml
.
main.xml
by the following Java command in the MainActivity.java
:
setContentView( R.layout.main );
The story took on a life of its own and began to appear on news broadcasts everywhere. |