How do I pass info between fragments and activities with an EditText?












0














Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?



public class WebpageSetter_Fragment extends Fragment {

EditText direccion1, direccion2;
Button cambiarUrl;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}









share|improve this question




















  • 1




    so, in simple words, you want to communicate between fragments, right?
    – Touhidul Islam
    Nov 11 at 11:09










  • Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
    – Jorge Hetfield
    Nov 11 at 17:42
















0














Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?



public class WebpageSetter_Fragment extends Fragment {

EditText direccion1, direccion2;
Button cambiarUrl;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}









share|improve this question




















  • 1




    so, in simple words, you want to communicate between fragments, right?
    – Touhidul Islam
    Nov 11 at 11:09










  • Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
    – Jorge Hetfield
    Nov 11 at 17:42














0












0








0







Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?



public class WebpageSetter_Fragment extends Fragment {

EditText direccion1, direccion2;
Button cambiarUrl;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}









share|improve this question















Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?



public class WebpageSetter_Fragment extends Fragment {

EditText direccion1, direccion2;
Button cambiarUrl;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}






android android-fragments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:23









Alex Kolydas

304114




304114










asked Nov 11 at 10:47









Jorge Hetfield

1




1








  • 1




    so, in simple words, you want to communicate between fragments, right?
    – Touhidul Islam
    Nov 11 at 11:09










  • Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
    – Jorge Hetfield
    Nov 11 at 17:42














  • 1




    so, in simple words, you want to communicate between fragments, right?
    – Touhidul Islam
    Nov 11 at 11:09










  • Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
    – Jorge Hetfield
    Nov 11 at 17:42








1




1




so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09




so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09












Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42




Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42












2 Answers
2






active

oldest

votes


















0














Use this code



EditText direccion1, direccion2;
Button cambiarUrl;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
direccion2 = view.findViewById(R.id.your_edittext_id);
//same for the other edittext
//If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff

return view;
}


This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use



linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);





share|improve this answer





















  • Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
    – Jorge Hetfield
    Nov 11 at 11:05










  • If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code, if(editText.getText().toString()!=null){ your stuff} , if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
    – Wedprakash Wagh
    Nov 11 at 11:07












  • Post the error you're getting so that I'd understand what the actual problem is.
    – Wedprakash Wagh
    Nov 11 at 11:22



















0














Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247972%2fhow-do-i-pass-info-between-fragments-and-activities-with-an-edittext%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Use this code



    EditText direccion1, direccion2;
    Button cambiarUrl;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
    direccion2 = view.findViewById(R.id.your_edittext_id);
    //same for the other edittext
    //If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff

    return view;
    }


    This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use



    linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);





    share|improve this answer





















    • Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
      – Jorge Hetfield
      Nov 11 at 11:05










    • If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code, if(editText.getText().toString()!=null){ your stuff} , if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
      – Wedprakash Wagh
      Nov 11 at 11:07












    • Post the error you're getting so that I'd understand what the actual problem is.
      – Wedprakash Wagh
      Nov 11 at 11:22
















    0














    Use this code



    EditText direccion1, direccion2;
    Button cambiarUrl;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
    direccion2 = view.findViewById(R.id.your_edittext_id);
    //same for the other edittext
    //If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff

    return view;
    }


    This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use



    linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);





    share|improve this answer





















    • Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
      – Jorge Hetfield
      Nov 11 at 11:05










    • If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code, if(editText.getText().toString()!=null){ your stuff} , if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
      – Wedprakash Wagh
      Nov 11 at 11:07












    • Post the error you're getting so that I'd understand what the actual problem is.
      – Wedprakash Wagh
      Nov 11 at 11:22














    0












    0








    0






    Use this code



    EditText direccion1, direccion2;
    Button cambiarUrl;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
    direccion2 = view.findViewById(R.id.your_edittext_id);
    //same for the other edittext
    //If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff

    return view;
    }


    This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use



    linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);





    share|improve this answer












    Use this code



    EditText direccion1, direccion2;
    Button cambiarUrl;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
    direccion2 = view.findViewById(R.id.your_edittext_id);
    //same for the other edittext
    //If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff

    return view;
    }


    This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use



    linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 11 at 10:58









    Wedprakash Wagh

    11




    11












    • Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
      – Jorge Hetfield
      Nov 11 at 11:05










    • If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code, if(editText.getText().toString()!=null){ your stuff} , if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
      – Wedprakash Wagh
      Nov 11 at 11:07












    • Post the error you're getting so that I'd understand what the actual problem is.
      – Wedprakash Wagh
      Nov 11 at 11:22


















    • Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
      – Jorge Hetfield
      Nov 11 at 11:05










    • If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code, if(editText.getText().toString()!=null){ your stuff} , if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
      – Wedprakash Wagh
      Nov 11 at 11:07












    • Post the error you're getting so that I'd understand what the actual problem is.
      – Wedprakash Wagh
      Nov 11 at 11:22
















    Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
    – Jorge Hetfield
    Nov 11 at 11:05




    Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
    – Jorge Hetfield
    Nov 11 at 11:05












    If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code, if(editText.getText().toString()!=null){ your stuff} , if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
    – Wedprakash Wagh
    Nov 11 at 11:07






    If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code, if(editText.getText().toString()!=null){ your stuff} , if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
    – Wedprakash Wagh
    Nov 11 at 11:07














    Post the error you're getting so that I'd understand what the actual problem is.
    – Wedprakash Wagh
    Nov 11 at 11:22




    Post the error you're getting so that I'd understand what the actual problem is.
    – Wedprakash Wagh
    Nov 11 at 11:22













    0














    Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.






    share|improve this answer


























      0














      Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.






      share|improve this answer
























        0












        0








        0






        Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.






        share|improve this answer












        Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 14:15









        Taha wakeel

        896




        896






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247972%2fhow-do-i-pass-info-between-fragments-and-activities-with-an-edittext%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Hercules Kyvelos

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud