Skip to content Skip to sidebar Skip to footer

How To Pass Get Text From Userinput (edittext) And Put Into A Textview In Another Activity?

I would like to take user input entered in the EditTextField(in the EnterNewFile class) and put it into the TextField (in the NoteEdit class). Please help! Thanks! FYI- I use X

Solution 1:

Take the input from Edittext send it through the Intent to your destination activity and then set it in the TextView there.

I think you seem to already be doing that in your code: The issue might be the you've not defined in your XML that nextButton function should be call on click ( inside android:onClick: inside your Button).

What you can also do is, in your onCreate funcion set up a listener which listens to the button click and call the intent from within it.

final EditText editText = (EditText) findViewById(R.id.file_name_edittext);
mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            /** Called when the user clicks the Next button */
            Log.d("EditText", mText.getText().toString());
            Intent intent = new Intent(EnterNewFile.this, NoteEdit.class);
            String message = editText.getText().toString();
            intent.putExtra(EXTRA_MESSAGE, message);
            startActivity(intent);
        }
    });
//here you are taking value from EditText and send it to other activity:

Instead of

 // Get the message from the intent
 Intent intent = getIntent();
 String message = intent.getStringExtra(EnterNewFile.EXTRA_MESSAGE);

use following in onCreate() of your other NoteEdit activity:

Intent intent = getIntent(); 
if((intent.getExtras()!=null) && !intent.getExtras().isEmpty()){
    String message = intent.getExtras().getString(EnterNewFile.EXTRA_MESSAGE);
}

Solution 2:

this code is working:-

    scrollview=(ScrollView)findViewById(R.id.scrollview1); 
    tb2.setTextSize(30); 
    tb2.setMovementMethod(new ScrollingMovementMethod());
    scrollview.post(new Runnable() { 
    public void run() { 
        scrollview.fullScroll(View.FOCUS_DOWN);  
        }
    }); 
    chat1.setOnClickListener(new OnClickListener() { 
        public void onClick(View v) { 
         {
             textsaring1=edt1.getText().toString();
             tb2.setText(tb2.getText()+" "+textsaring1);
             edt1.setText("");
        } 
        }
    });  

Post a Comment for "How To Pass Get Text From Userinput (edittext) And Put Into A Textview In Another Activity?"