Designing the layout of the screen

Let's design the screen that will accept the factors of the model we created as input. The screen will have seven input boxes to accept the factors, one button, and an output textbox to display the predicted result:

Traverse to the layout folder in res and select the activity_layout.xml file to open in the editing panel. Choose the Text option at the bottom to view the existing XML for the layout:

Now, replace the existing XML code with the new design template for the app. Please refer to the activity_layout.xml code file in the Android folder for the full design template. The following is only a skeletal reference of the XML code template:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/bizprop"/>
<EditText
android:id="@+id/bizprop-edit"/>
<TextView
android:id="@+id/rooms"/>
<EditText
android:id="@+id/rooms-edit"/>
<TextView
android:id="@+id/age"/>
<EditText
android:id="@+id/age-edit"/>
<TextView
android:id="@+id/highways"/>
<EditText
android:id="@+id/highways-edit"/>
<TextView
android:id="@+id/tax"/>
<EditText
android:id="@+id/tax-edit"/>
<TextView
android:id="@+id/ptratio"/>
<EditText
android:id="@+id/ptratio-edit"/>
<TextView
android:id="@+id/lstat"/>
<EditText
android:id="@+id/lstat-edit"/>
<Button
android:id="@+id/button"/>
<TextView
android:id="@+id/value"/>
</RelativeLayout>
</ScrollView>

Here, we have designed a layout to accept the seven factors as input, as follows:

  • BIZPROP: Proportion of non-retail business acres per town
  • ROOMS: Average number of rooms per dwelling
  • AGE: Proportion of owner-occupied units built prior to 1940
  • HIGHWAYS: Index of accessibility to radial highways
  • TAX: Full-value property-tax rate per $10,000
  • PTRATIO: Pupil-to-teacher ratio by town
  • LSTAT: Percentage of lower status of the population

There is also a button and a textbox to display the output. The predicted value is displayed when the button is clicked.

To view the design of the activity, run the Run app option in the run menu from the top menu bar. The first time you run it, the environment will ask you to create a virtual device to test your app. You can either create an Android Virtual Device (AVD) or use the traditional method, that is, use an USB cable to connect your Android phone to the PC so that you can run the output directly on your device:

You should see the design of the scrollable layout once the app starts on the device or AVD emulator:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset