Lab # 7

Description

The main purpose of this lab was to download and install Android SDK and make a simple app by following the tutorials in the android developer website. Therefore the steps required to accomplish this task are in the following; first, I had to assigned the app’s name, function and layout this can be done in the “strings.xml” located at scr\values. Second, I had to specify the layout dimensions and sizes for each element on the app such as; buttons, contents, and menus all these can be done in the “activity_main.xml” located at \res\layout. Third, I had to create a class called sendMessage with its respective method in order to send a message on the app. Step three can be done in the “MainAcitivity” java file located at \src. Therefore, After setting all the required elements I compiled all programs and run it using the Android Virtual Device Manager.

 

Codes

MainActivity

 //Tax, Julio 
package com.example.myfirstapp;

import android.view.InputEvent;
import android.view.View;
import android.view.View;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.EditText;

public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
Intent intent1 = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent1.putExtra(EXTRA_MESSAGE, message);
}
}

 main.xml

// Tax, Julio
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>

strings.xml

 //Tax, Julio
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My First App</string>
<string name="edit_message">Enter a message</string>
<string name="button_send">Send</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="action_settings">title</string>
</resources>

Screenshots