250 likes | 412 Views
Android Boot Camp. Demo Application – Part 1. Development Environment Set Up. Download and install Java Development Kit (JDK) Download and unzip Android ADT, download SDK Manager packages Instructions are here:
E N D
Android Boot Camp Demo Application – Part 1
Development Environment Set Up • Download and install Java Development Kit (JDK) • Download and unzip Android ADT, download SDK Manager packages • Instructions are here: https://developer.motorolasolutions.com/community/developer-events/appforum-2014/android-boot-camp/blog/2014/09/07/appforum-android-boot-camp--hands-on-lab
Create a new Android Project, in this case, the name is “Appforum1”
Set the name of the Run Configuration to match your Application
Go back into the graphical layout designer, Select Text Fields Tab
Add the definitions for “textOutput” and “textInput” Add the code to get the references to the XML objects Add 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 TextViewtextOutput; private EditTexttextInput;
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 booleanonKey(View v, intkeyCode, 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(""); }