android boot camp demo application – part 1. development environment set up download and install...

25
Android Boot Camp Demo Application – Part 1

Upload: godfrey-norman

Post on 13-Dec-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Android Boot Camp

Demo Application – Part 1

Create a new Android Project, in this case, the name is “Appforum1”

Take Default Options

Take Default Options

Take Default Options, Create Blank Activity

Take Default Options

Basic “Hello world” Application is Generated

Create a “Run Configuration”

Run Configuration for Android Application

Browse to your project

Set the name of the Run Configuration to match your Application

Select an AVD or Android Device

Apply and Run

Application runs in Emulator

Go back into the graphical layout designer, Select Text Fields Tab

Add a Text Input Field (editText1)

Add a Button (button1) from “Form Widgets”

Define a Listener for “On Click” for the Button

Add the definitions for “textOutput” and “textInput”Add the code to get the references to the XML objectsAdd the code to get keystrokes, use “Ctl”-”Shift”-”O” to Organize Imports

Add code for button and to move text from input to output fields

Code Fragments 1

After: “public class MainActivity extends ActionBarActivity {”

Insert:

private TextView textOutput; private EditText textInput;

Code Fragments 2

After: “protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);”

Insert:

textOutput = (TextView)findViewById(R.id.textView1); textInput = (EditText)findViewById(R.id.editText1); textInput.setOnKeyListener(new EditText.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) {

if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) TransferInput(); return false; }

});

Code Fragments 3

At the end of your application before the final “}”, insert :

public void Button1Clicked (View v) {

TransferInput(); } public void TransferInput(){ String input; input = textInput.getText().toString();

textOutput.setText(input); textInput.setText(""); }

Congratulations, you have completed your first Application!