Let’s start by designing the user interface for our screen where we’ll enter the new status and click a button to update it.
By default, Eclipse
created a file called main.xml under the
folder. For consistency purposes, we should rename this file to
status.xml to match
our StatusActivity. To rename a file in Eclipse, right-click on it,
choose Refactor→Rename…, and enter the
new name. Eclipse is somewhat smart about renaming files and does
more than just change the name. It also offers to look up all references
to this file and update those as well. Although this feature works well
when renaming a Java file, it is not fully automatic with XML files. So,
renaming this file requires us to change the line in Java where we refer
to it via the
R class. To do that, in
This screen will have four components:
A title at the top of the screen. This will be a
A big text area to type our 140-character status
update. We’ll use an
widget for this purpose.
A button to click to update the status. This will be a
A layout to contain all these widgets and lay them out one
after another in a vertical fashion. For this screen, we’ll use
LinearLayout, one of the more
Example 6-1 contains the source code for our StatusActivity layout.
Example 6-1. res/layout/status.xml
<?xml version="1.0" encoding="utf-8"?> <!-- Main ...