Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Android Tutorial: Part 1 Creating a Simple Edit Text Box and Button 1 • Follow the tutorial: • http://developer.android.com/training/index.html • Start the tutorial from: – Creating an Android Project • End the tutorial after you have completed: – Building a Simple User Interface 2 • After running your application on the emulator, You should end up with the following: 3 Instruction 3: Building a Simple User Interface • Under Section “Create a Linear Layout”, replace the text “activity_my.xml” with “content_my.xml”. Note that the “activity_my.xml” file includes the “content_my.xml” file. • • Find line: “Here’s how your complete activity_my.xmllayout file should now look: Change the code that follwos the above line to as follows: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <EditText android:id="@+id/edit_message" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="@string/edit_message" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" /> </LinearLayout> 4 Instruction 4: Running a Simple User Interface • After running your application on the emulator, You should end up with the following: 5 Instructions 5: Refactoring • Manually change the names of the following widgets: – EditText id from edit_message to: my_message – EditText hint from edit_message to: my_message – Button text string from button_send to: my_button • Ensure you change the entries in strings.xml • Run the app to verify it still compiles successfully and displays as before. • Using the Refactor feature of the IDE, change the names of the following widgets: – EditText id from my_message to: IP_Address_Text – EditText hint from my_message to: my_message – Button text string from my_button to: IP_Address_Button • Run the app to verify it still compiles sucessfuly and displays as before. 6 Instructions 6: Adding a Method for a Button • In file content_my.xml file: – Append the following to the Button widget: android:onClick=“IPButtonPressed” – Add the following method to the MyActivity.java file: public void IPButtonPressed(View view) { EditText myIPAddressTextBox = (EditText)findViewById(R.id.IP_Address_Text); String theIPAddress = myIPAddressTextBox.getText().toString(); } – Place a breakpoint at the ending brace of the IPButtonPressed method. – Debug the app, enter an IP address in the box, and then verify the string theIPAddress has your item. 7