Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jtmnf.petapp;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class ChangeName extends AppCompatActivity {
- private TextView owner;
- private TextView petName;
- private TextView pet;
- private Button button;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_change_name);
- // Init the various views in this activity
- owner = findViewById(R.id.owner);
- petName = findViewById(R.id.petName);
- button = findViewById(R.id.button2);
- pet = findViewById(R.id.textView4);
- // Get information sent from the calling activity
- Intent intent = getIntent();
- String petToChange = intent.getStringExtra("selected");
- // Set the name in the textView from this activity (it was optional)
- pet.setText(petToChange);
- // Set a click listener for the button
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // Start the intent
- Intent intent = new Intent();
- // Pass the texts in the editTexts to the intent
- intent.putExtra("owner", owner.getText().toString());
- intent.putExtra("petName", petName.getText().toString());
- // Inform the the result was ok and the correspondent intent
- // By calling the setResult, it will return to the calling activity
- setResult(RESULT_OK, intent);
- // Destroy the activity (to free memory and other resources)
- finish();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement