Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access the content of EditText when back button is pressed

I'm working with fragments. Suppose I have fragmentA and fragmentB and I can go from fragmentA to fragmentB. In fragmentA I have a form (several edit texts). If I fill the form and then go to fragmentB and then press back button, all the information that I typed in the form is retained. From onCreateView I'm trying to do

String name = myEditText.getText().toString();

But I get empty result, even when I'm seeing the values in the form.

The question is, how can I access the content of this EditText in this situation?.

Solution

    public void onResume() {
    super.onResume();
    String id = etIdHidden.getText().toString();

    if(id.equals("")==false){

                    //Here do whatever you need, in my case I needed to change a bundle
        mArgumentos=new Bundle();
            mArgumentos.putString("id", ""+id);

    }

};
like image 321
kiduxa Avatar asked Dec 08 '25 09:12

kiduxa


1 Answers

Try fetching the value from the editText in the onResume() method. Also refer to the life-cycle of the fragment in the docs http://developer.android.com/guide/components/fragments.html

like image 131
S.A.Norton Stanley Avatar answered Dec 09 '25 22:12

S.A.Norton Stanley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!