Home > DeveloperSection > Forums > How to set textview from another activity using intent extra?
Brad Pitt
Brad Pitt

Total Post:61

Points:429
Posted on    October-14-2014 1:45 AM

 Android Android  Mobile Development 
Ratings:


 2 Reply(s)
 1418  View(s)
Rate this:

I am trying to get a text view to update after a user has typed in a string from another result. When using this method below I get what appears to be the edit text's code address. Something like "android.widget.Edittext(b142f388 etc." regardless of what the user types in on the other activity. What am I missing here?

String collected from user:

private void enterClicked() {


    Log.i(TAG,"Entered enterClicked()");


    //Save user provided input from the EditText field

    String result = mEditText.toString();


    //Create a new intent and save the input from the EditText field as an extra

    Intent i = new Intent(ExplicitlyLoadedActivity.this, ActivityLoaderActivity.class);

    i.putExtra("RESULT_STRING", result);


    //Set Activity's result with result code RESULT_OK

    setResult(RESULT_OK, i);


    //Finish the Activity

    finish();


}

Activity Result:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {


    Log.i(TAG, "Entered onActivityResult()");


    // RESULT_OK result code and a recognized request code

    // If so, update the Textview showing the user-entered text.


    if ( resultCode == RESULT_OK){

        if(requestCode == GET_TEXT_REQUEST_CODE){           

        String userData = data.getStringExtra("RESULT_STRING");

        mUserTextView.setText(userData);

    }    

}

}



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Supported
Posted on    October-14-2014 1:47 AM

You need to use getText() method to get text from editText:

Try using this code: String result = mEditText.getText().toString();

private void enterClicked() {

    Log.i(TAG,"Entered enterClicked()");

    //Save user provided input from the EditText field
    String result = mEditText.toString();

    //Create a new intent and save the input from the EditText field as an extra
    Intent i = new Intent(ExplicitlyLoadedActivity.this, ActivityLoaderActivity.class);
    i.putExtra("RESULT_STRING", result);

    //Set Activity's result with result code RESULT_OK
    setResult(RESULT_OK, i);

    //Finish the Activity
    finish();

}

ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    October-14-2014 1:48 AM

First apply this and check result.

String result = mEditText.getText().toString();

Don't want to miss updates? Please click the below button!

Follow MindStick