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

Asked

Viewed 2,400 times

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" />

Then I wanted you to show the data on another screen in this 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" />

  • tries to search a little more before asking here, in a few minutes you would find it on youtube

1 answer

2


you have to send the data of one Act and receive them in the other

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

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

    }

just vc replace the data and put this code in your application!

  • All right, young man!!!

  • Just one thing? If I don’t type anything and click on the button doesn’t appear Else’s message? if(!Bundle.isEmpty()){ String result = Bundle.getString("Result"); textView2.setText(result); }Else{ String error = "Error!! 404"; textView2.setText(error); }

  • then usually it happens cmg, you have to find the problem, test to see what is happening, maybe the comparison method tries to use what was, Bundle != null, sometimes he’s reading this "" as a value, trying to pass a more specific value, like if the guy didn’t write anything, sends a character that identifies it

  • A Toast??? So...

  • can be a Toast yes

Browser other questions tagged

You are not signed in. Login or sign up in order to post.