Android Boot Camp Project Part 1 Walk Through

Version 3

    This is a walk through of part 1 of the Boot Camp project.  The code snippets are repeated here:

    1. After: “public class MainActivity extends ActionBarActivity {”

         Insert:     

              private TextView textOutput;          

               private EditText textInput;

     

    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; }     

                   });

     

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