How do I display the data in an EditText of an Activity in another Activity?

1
package com.example.alinesilvagonzaga.teste;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private EditText editText;
private TextView textView;
private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editText = (EditText) findViewById(R.id.editText);
    textView = (TextView) findViewById(R.id.textView);
    button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Editable result = editText.getText();
            textView.setText(result.toString());
            Intent intent = new Intent(this, Main2Activity.class);
                intent.s
        }
    });
}

}

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:id="@+id/textView"/>

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:layout_marginTop="73dp"
    android:id="@+id/editText" />

<Button
    android:text="Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText"
    android:layout_alignParentStart="true"
    android:layout_marginStart="41dp"
    android:layout_marginTop="73dp"
    android:id="@+id/button" />

Here I wanted to display the data on another screen in the below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="com.example.alinesilvagonzaga.teste.Main2Activity">

<TextView
    android:text="TextView"
    android:layout_width="218dp"
    android:layout_height="84dp"
    android:id="@+id/textView2" />

    
asked by anonymous 27.11.2016 / 20:49

1 answer

2

You have to send the data of one act and receive them in the other

to send you use the method putExtra first parameter is a key and the second the given

 Intent intent = new Intent(Anotacoes_Carregar.this, Anotacoes_visualizar.class);

            intent.putExtra("_id", id);
            intent.putExtra("anotacao", anotacao);

startActivity(intent); 

To receive the data you have to use a bundle object

    Bundle bundle = getIntent().getExtras();
    if(bundle != null){

        String id = bundle.getString("_id");
        String anotacao = bundle.getString("anotacao);

    }

Simply replace the data and put this code in your application!

    
27.11.2016 / 21:02