Android Coding Questions

How to add question ?

Log into wiki, find this question (index) page, and add a question beginning the this page, after first headline.

==== My Problem ? ====
How to get functionality X to work ?

How do I start another activity?

startActivity(new Intent(this, MyAnotherActivity.class));

+ Don't forget to add lines in AndroidManifest.xml

How to add EditText fields to the table's cells?

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:stretchColumns="*">
<TableRow android:id="@+id/tablerow1">
<EditText android:text="1." android:id="@+id/EditText01"
android:editable="false"></EditText>
<EditText android:id="@+id/EditText11"></EditText>
<EditText android:id="@+id/EditText21"></EditText>
</TableRow>
</TableLayout>

How to save XML file after editing (f.e. adding new child) - what class to use?

To use XmlSerializer is one option to save XML into readable form (string or file).

See the following link Working with XML on Android if that is helpful.

private String writeXml(List<Message> messages){
XmlSerializer serializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
try {
serializer.setOutput(writer);
serializer.startDocument("UTF-8", true);
serializer.startTag("", "messages");
serializer.attribute("", "number", String.valueOf(messages.size()));
for (Message msg: messages){
serializer.startTag("", "message");
serializer.attribute("", "date", msg.getDate());
serializer.startTag("", "title");
serializer.text(msg.getTitle());
serializer.endTag("", "title");
serializer.startTag("", "url");
serializer.text(msg.getLink().toExternalForm());
serializer.endTag("", "url");
serializer.startTag("", "body");
serializer.text(msg.getDescription());
serializer.endTag("", "body");
serializer.endTag("", "message");
}
serializer.endTag("", "messages");
serializer.endDocument();
return writer.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

How to answer a question ?

Just write a solution text into section, after question.

If solution is bigger that one paragraph size (having eg. couple screenshots), it is good idea document solution into separate page.

Solution in [[separate page]]