How to get string from edit text and pass to new activity?

how to pass multiple edittext value to another activity in android
how to pass edittext value from one activity to another activity in android
access textview from another activity
how to pass textview value from one activity to another activity in android
how to send string from one activity to another in android
how to set value in edittext in android
get string from edittext android
how to send text from one activity to another in android studio

I am trying to collect user input and pass it to another activity and display it using text view.

I have tried using the getText() and toString() functions and passing the intent, but when running the program the strings that should contain the user input is not displayed properly.

protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main_in);

            //Collect user inputs and store them in strings
            noun1 = (EditText)findViewById(R.id.noun1);
            pluralNoun =  (EditText)findViewById(R.id.pluralNoun);
            noun2 = (EditText)findViewById(R.id.noun2);
            place = (EditText)findViewById(R.id.place);
            adjective = (EditText)findViewById(R.id.adjective);
            noun3 = (EditText)findViewById(R.id.noun3);

            firstNoun = noun1.getText().toString();
            nounPlural = pluralNoun.getText().toString();
            secondNoun = noun2.getText().toString();
            inputPlace = place.getText().toString();
            inputAdjective = adjective.getText().toString();
            thirdNoun = noun3.getText().toString();

            madLib ="Be kind to your " + firstNoun + "-footed " + pluralNoun + "\n" +
                    "For a duck may be somebody`s " + secondNoun + ",\n" +
                    "Be kind to your " + pluralNoun + " in " + inputPlace + "\n" +
                    "Where the weather is always " + inputAdjective + ".\n" +
                    "\n" +
                    "You may think that this is the " + thirdNoun + ",\n" +
                    "Well it is.\t";

        }



        public void createStory(View view) {
            Intent myIntent = new Intent(MainActivityIn.this,
                    MainActivityOut.class);
            myIntent.putExtra("story",madLib);
            startActivity(myIntent);
        }

I expect an output of a few sentences displaying the story with the words that the user entered but instead, I get the output pictured below:

You can retrieve your String in your another activity called MainActivityOut.class using below code and pass that string to your text view.

String madLib = getIntent().getStringExtra("story");
yourTextView.setText(madLib);

How to get string from edit text and pass to new activity?, You can retrieve your String in your another activity called MainActivityOut.class using below code and pass that string to your text view. String� Send EditText entered selected value to another android activity on button click and receive+set into textview. Some of android application developer want to get edittext value then set that selected value inside textview placed on second next activity.

In matLib some of the variable you calling are not String but editText, that's why you have those weird result. Like pluralNoun... Try this naming convention, name all editText et..., all textView tv..., all button btn..., all imageView iv... This way you can avoid confusion about your variables.

Passing Edit Text Value From One Activity to Another Activity , Hello Friends! In this android tutorial, I'm showing you how to make an android app that pass Duration: 10:31 Posted: 10 Mar 2018 For this lesson we are only concerned with passing data between activities without making them persistent so we’ll look at the two simplest ways to achieve that which are by using Static methods and Intents

you are passing EditText Object inside string

madLib ="Be kind to your " + firstNoun + "-footed " + pluralNoun + "\n" +
                    "For a duck may be somebody`s " + secondNoun + ",\n" +
                    "Be kind to your " + pluralNoun + " in " + inputPlace + "\n" +
                    "Where the weather is always " + inputAdjective + ".\n" +
                    "\n" +
                    "You may think that this is the " + thirdNoun + ",\n" +
                    "Well it is.\t";

pluralNoun is EditText Object

change code like

madLib ="Be kind to your " + firstNoun + "-footed " + nounPlural+ "\n" +
                        "For a duck may be somebody`s " + secondNoun + ",\n" +
                        "Be kind to your " + nounPlural + " in " + inputPlace + "\n" +
                        "Where the weather is always " + inputAdjective + ".\n" +
                        "\n" +
                        "You may think that this is the " + thirdNoun + ",\n" +
                        "Well it is.\t";

Passing data between Activities using Intent in Android, Through Intent we can move from one activity to another activity and Intent… EditText edittextfullname,edittextusername; : This is the way to define the gets the string form LoginActivity and in parameter, we have to pass� We have used getText() method to get the text entered in the EditText views. But getText() method returns an Editable instance and therefore we have typecasted it to convert it into String for further use. This can be done by using the toString() method.

Passing Data from One Activity to Another Activity � GitHub, Passing Data from One Activity to Another Activity. MainActivity.java EditText;. public class MainActivity extends Activity {. private Button button;. Bundle bundle;. String value; a button name which I have given in XML file. */. This has to be a String. We have used the String "HELLO_MESSAGE", but you can use almost anything here: you can replace the direct text that we have with a variable, if you want, or even set up a constant at the top of your code and use that. After a comma, you then type the text you want to use as the value for the key.

Get Value from the EditText and Set value to the TextView, In this tutorial we will learn how to take input from the user through EditText view in Android and display it Android Activity, Intents and Fragments setOnClickListener(new View. get text from EditText name view String name = editName. Intent intent = new Intent(getApplicationContext(), Second_activity.class); where getApplicationContext() will fetch the current activity. Put the value in putExtra method in key value pair then start the activity.

How to pass multiple data from one activity to another in Android?, MainActivity"> <EditText android:id = "@+id/etName" android:layout_width putString("age", age); Intent intent = new Intent(MainActivity.this, SecondActivity. class); intent. getString("name"); String age = bundle. Call startActivity(intent) method in source activity to pass the intent to android os. Call getIntent() method in target activity. Use intent.getStringExtra(String key) to get the transferred data. 3. Get Response Result Data Back From Target Activity. Create a New Explicit or Implicit Intent object in source activity. Call intent.putExtra(String key, Object data) method to save data in it.

Comments
  • Possible duplicate of How to pass two Strings from one Activity to another Activity in Android
  • Hi Yabba, welcome to SO, please have a research before placing a question. We already have many questions for this task :)