COMP 365 Android Development
Developing for Android XML for user interface formatting and other scripting Java for programming
XML is a markup language Uses tags to contain data like so data Can close tags without using data like so Can contain attributes Can nest tags within each other
main_activity.xml under res-> layout in Eclipse to change the XML Change the layout by changing the first tag LinearLayout RelativeLayout WebView Attributes for layout android:layout_width android:orientation
EditText Add within the layout tag Attributes android:layout_width & android:layout_height android:id Adding a string to display in the textbox Res → values → string in Ecplise text
Under res → layout Button Attributes android:text Link to the string resource android:text =
Adding an onClick event to the button Attribute – android:onClick=”functionName” FunctionName has a View object as a parameter, and returns void
When the onClick event activates, bring up an Alert Dialog //Create a new Dialog AlertDialog.Builder alert = new AlertDialog.Builder( this ); //Get a reference to the EditText field EditText userInput = (EditText)findViewById(R.id.edit_message); //Get the text from the EditText field String message = userInput.getText().toString(); //Name of the Dialog alert.setTitle(“User input is:”); //Name of the message alert.setMessage( message ); //Give the Dialog an “Ok” button, not necessary though alert.setPositiveButton(“Ok”, null); //show the dialog alert.show();