How to read and display data in Android Studio?

Asked

Viewed 558 times

-4

How to read the data typed by the user in an Edittext and display in a new Activity in Android Studio? I’ve tried a few ways, but when showing it in the other Activity only appears "false".

  • Post the way you tried. Without your code, hardly anyone can help you.

1 answer

0

Tip:

Learn Java or Kotlin before you start, it will be very good for your knowledge, because Android revolves around these languages of object-oriented programming.

How To Do:

private EditText mEditText;
mEditText = findViewById(R.id.NOME_DA_ID);

public void onClickButton(){
    Button mBtn= findViewById(R.id.NOME_DA_ID);
    mBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bundle bundle = new Bundle();
            bundle.putString("TAG", mEditText.getText());
            Intent intent = new Intent(this, OutraActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
            finish();
        }
    });
}

Observing:

Edittext: Class that has all the context from where you are typing the value, create a private variable and create get and set from it to insert and pick values;

Bundle: You will pass the information you want to another Activity, through a "TAG";

Intent: Will change Activity along with the Bundle to pass the information to another Activity;

Browser other questions tagged

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