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
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
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(""); }