Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. package com.jtmnf.petapp;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.TextView;
  10.  
  11. public class ChangeName extends AppCompatActivity {
  12.  
  13. private TextView owner;
  14. private TextView petName;
  15. private TextView pet;
  16. private Button button;
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_change_name);
  22.  
  23. // Init the various views in this activity
  24. owner = findViewById(R.id.owner);
  25. petName = findViewById(R.id.petName);
  26. button = findViewById(R.id.button2);
  27. pet = findViewById(R.id.textView4);
  28.  
  29.  
  30. // Get information sent from the calling activity
  31. Intent intent = getIntent();
  32. String petToChange = intent.getStringExtra("selected");
  33.  
  34. // Set the name in the textView from this activity (it was optional)
  35. pet.setText(petToChange);
  36.  
  37. // Set a click listener for the button
  38. button.setOnClickListener(new View.OnClickListener() {
  39. @Override
  40. public void onClick(View v) {
  41. // Start the intent
  42. Intent intent = new Intent();
  43.  
  44. // Pass the texts in the editTexts to the intent
  45. intent.putExtra("owner", owner.getText().toString());
  46. intent.putExtra("petName", petName.getText().toString());
  47.  
  48. // Inform the the result was ok and the correspondent intent
  49. // By calling the setResult, it will return to the calling activity
  50. setResult(RESULT_OK, intent);
  51.  
  52. // Destroy the activity (to free memory and other resources)
  53. finish();
  54. }
  55. });
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement