Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. package course.labs.intentslab;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11.  
  12. public class ExplicitlyLoadedActivity extends Activity {
  13.  
  14.     static private final String TAG = "Lab-Intents";
  15.  
  16.     private EditText mEditText;
  17.    
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.        
  22.         setContentView(R.layout.explicitly_loaded_activity);
  23.  
  24.         // Get a reference to the EditText field
  25.         mEditText = (EditText) findViewById(R.id.editText);
  26.  
  27.         // Declare and setup "Enter" button
  28.         Button enterButton = (Button) findViewById(R.id.enter_button);
  29.         enterButton.setOnClickListener(new OnClickListener() {
  30.  
  31.             // Call enterClicked() when pressed
  32.  
  33.             @Override
  34.             public void onClick(View v) {
  35.  
  36.                 enterClicked();
  37.            
  38.             }
  39.         });
  40.  
  41.     }
  42.  
  43.     // Sets result to send back to calling Activity and finishes
  44.    
  45.     private void enterClicked() {
  46.  
  47.         Log.i(TAG,"Entered enterClicked()");
  48.        
  49.         // TODO - Save user provided input from the EditText field
  50.  
  51.         // TODO - Create a new intent and save the input from the EditText field as an extra
  52.         Intent resultIntent = new Intent();
  53.             resultIntent.putExtra("text", mEditText.getText());
  54.  
  55.         // TODO - Set Activity's result with result code RESULT_OK
  56.         setResult(RESULT_OK, resultIntent);
  57.  
  58.  
  59.         // TODO - Finish the Activity
  60.         finish();
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement