34,333
edits
Changes
no edit summary
== Creating the Database Project ==
Start Eclipse and create a new Android Application project named Database using the appropriate Android SDK versions, a package name of com.example.database and including a blank activity named DatabaseActivity with a corresponding layout file and fragment files named activity_databaseand fragment_database.
== Designing the User Interface Layout ==
If it is not already displayed, locate the activity_databasefragment_database.xml file in the Package Explorer panel and double click on it to load it into the Graphical Layout tool. Once loaded, select the example TextView object from the layout and press the keyboard Delete key to remove it from the layout. Next, switch to the XML view and remove the padding properties so that the file reads as follows:
<pre>
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context= "com.example.database.DatabaseActivity$PlaceholderFragment" >
</RelativeLayout>
</pre>
<google>BUY_ANDROID</google>
Modify the properties of the views so that they display text that reads “Product ID” and “ID Not Assigned” respectively, making sure to create new string resources for each label. Change the ID of the right hand TextView to productID. This can be achieved either by right-clicking on the view in the visual layout and selecting the appropriate menu option, or by double clicking on the component and directly editing the appropriate XML elements in the activity_databasefragment_database.xml file.
Drag and drop another EditText and a Plain Text EditText view onto the second TableRow. Change the text on the TextView to Product Name and the ID of the EditText object to productName. With the Text View object selected in the layout, locate the Input Type property in the Property panel and change the type to text.
All that remains is to adjust some of the layout settings. In the first instance, right-click on the tableRow1 entry in the Outline panel and select the Other Properties -> Layout Parameters -> Layout Margin menu option and set the margin to 20dp. Repeat these steps for tableRow2 and tableRow3.
With these settings complete, the user interface should appear as illustrated in Figure 35-1. For the sake of completeness, and for comparison purposes in the event that your layout does not match that in Figure 35-1, the full activity_databasefragment_database.xml structure for this layout is outlined below.
<pre>