In Android m5 rc15, nested XML is not possible. Google should have included this feature because it is very useful. You don’t have to clutter your layouts inside 1 XML file. As with other web programming languages where you can do includes, Android doesn’t have it. So far, there has been no workaround made. I came upon one person who gave a solution but somehow it didn’t work. I always have this “layout_width must be set” problem. You can however load XML layouts at runtime using the ViewInflate class. But you need to have layout tags in your XML files and retrieve them via your code. For a quick sample, I had a separate article regarding this.
Here is a sample code to load XML layout files at runtime within your Android application. Basically, you have to have a Layout tag within your main XML file so that we get to have a placeholder to where we want to store our content.
where a is the class that extends Activity. If you are going to place this code within your class that extends Activity, you don’t need to include the a. in the code. Of course, this does not restrict to LinearLayout alone. You can use all other layouts to add new Views as its content.
In Java, we use System.out or System.err.println() to show messages in the console. However, these don’t work in Android. These methods do not produce errors on compilation and does nothing during runtime. Chris Glover made this nifty class to actually be able to use System.out and System.err in your programming needs.
Then you can use System.out and System.err.println(). If you want to convert Exception messages generated from the printStackTrace() method of Exception classes, use this Exception to String method converter that I have.
public static String getExceptionStackTraceAsString(Exception exception) { StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); return sw.toString(); }