HOW TO SET TEXTVIEW FROM ANOTHER ACTIVITY USING INTENT EXTRA?

Brad Pitt

Total Post:61

Points:429
Posted by  Brad Pitt
 1964  View(s)
Ratings:
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);

    }    

}

}

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to set textview from another activity using intent extra?

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

    }

  1. ezra heywood

    Post:145

    Points:1019
    Re: How to set textview from another activity using intent extra?

    First apply this and check result.


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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!