Display TextView when EditText is not empty












2















I'm working with an Android application and have encountered the following problem.



Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).



What I have done:



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
...

if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
textview.setText("some text")
}
return rootView;
}


This does not work. The text view never pops up. Any ideas why?










share|improve this question





























    2















    I'm working with an Android application and have encountered the following problem.



    Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).



    What I have done:



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
    savedInstanceState) {
    View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
    ...

    if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
    textview.setText("some text")
    }
    return rootView;
    }


    This does not work. The text view never pops up. Any ideas why?










    share|improve this question



























      2












      2








      2








      I'm working with an Android application and have encountered the following problem.



      Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).



      What I have done:



      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
      savedInstanceState) {
      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
      ...

      if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
      textview.setText("some text")
      }
      return rootView;
      }


      This does not work. The text view never pops up. Any ideas why?










      share|improve this question
















      I'm working with an Android application and have encountered the following problem.



      Problem: I want a TextView to display some text when two edittext fields are not empty (when there are text written in the edittext fields).



      What I have done:



      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
      savedInstanceState) {
      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
      ...

      if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
      textview.setText("some text")
      }
      return rootView;
      }


      This does not work. The text view never pops up. Any ideas why?







      android android-studio






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 11:12









      Fantômas

      32.5k156388




      32.5k156388










      asked Nov 19 '18 at 9:24









      JohnJohn

      718




      718
























          4 Answers
          4






          active

          oldest

          votes


















          4














          Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.



          TextWatcher textWatcher = new TextWatcher() {

          @Override
          public void onTextChanged(CharSequence s, int st, int b, int c)
          {

          }

          @Override
          public void beforeTextChanged(CharSequence s, int st, int c, int a)
          {

          }

          @Override
          public void afterTextChanged(Editable s)
          {
          if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
          textView.setVisibility(View.VISIBLE);
          textview.setText("some text");
          }
          }
          };

          edittextbox1.addTextChangedListener(textWatcher);
          edittextbox2.addTextChangedListener(textWatcher);





          share|improve this answer

































            3














            You need to use something like this to listen to your EditText fields.



            edittextbox1 = (EditText)findViewById(R.id.editText);

            edittextbox1.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int st, int b, int c)
            {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int st, int c, int a)
            {
            if(edittextbox1.getText().toString().length() !=0) {
            textview.setText("some text")
            }
            }

            @Override
            public void afterTextChanged(Editable s)
            {
            if(edittextbox1.getText().toString().length() !=0) {
            textview.setText("some text")
            }
            }
            });





            share|improve this answer
























            • Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?

              – John
              Nov 19 '18 at 9:39



















            0














            pls try set visibility of your textview



              @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
            savedInstanceState) {
            View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
            ...

            if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
            textview.setText("some text");
            textview.setVisibility(View.VISIBLE);
            }
            return rootView;
            }





            share|improve this answer
























            • this either won't work because he needs to listen to text changes

              – Vladyslav Matviienko
              Nov 19 '18 at 9:31



















            -1














            Do it like this. It will work!



            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
            savedInstanceState) {
            View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
            EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
            EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
            TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);

            if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
            textView.setVisibility(View.VISIBLE);
            textview.setText("some text");
            } else {
            textView.setVisibility(View.GONE);
            }
            return rootView;
            }





            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%2f53371579%2fdisplay-textview-when-edittext-is-not-empty%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.



              TextWatcher textWatcher = new TextWatcher() {

              @Override
              public void onTextChanged(CharSequence s, int st, int b, int c)
              {

              }

              @Override
              public void beforeTextChanged(CharSequence s, int st, int c, int a)
              {

              }

              @Override
              public void afterTextChanged(Editable s)
              {
              if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
              textView.setVisibility(View.VISIBLE);
              textview.setText("some text");
              }
              }
              };

              edittextbox1.addTextChangedListener(textWatcher);
              edittextbox2.addTextChangedListener(textWatcher);





              share|improve this answer






























                4














                Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.



                TextWatcher textWatcher = new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int st, int b, int c)
                {

                }

                @Override
                public void beforeTextChanged(CharSequence s, int st, int c, int a)
                {

                }

                @Override
                public void afterTextChanged(Editable s)
                {
                if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
                textView.setVisibility(View.VISIBLE);
                textview.setText("some text");
                }
                }
                };

                edittextbox1.addTextChangedListener(textWatcher);
                edittextbox2.addTextChangedListener(textWatcher);





                share|improve this answer




























                  4












                  4








                  4







                  Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.



                  TextWatcher textWatcher = new TextWatcher() {

                  @Override
                  public void onTextChanged(CharSequence s, int st, int b, int c)
                  {

                  }

                  @Override
                  public void beforeTextChanged(CharSequence s, int st, int c, int a)
                  {

                  }

                  @Override
                  public void afterTextChanged(Editable s)
                  {
                  if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
                  textView.setVisibility(View.VISIBLE);
                  textview.setText("some text");
                  }
                  }
                  };

                  edittextbox1.addTextChangedListener(textWatcher);
                  edittextbox2.addTextChangedListener(textWatcher);





                  share|improve this answer















                  Try this add TextWatcher to both edit text. You can get the text changed for both edit text and then you get the length and show your textView if the condition is true.



                  TextWatcher textWatcher = new TextWatcher() {

                  @Override
                  public void onTextChanged(CharSequence s, int st, int b, int c)
                  {

                  }

                  @Override
                  public void beforeTextChanged(CharSequence s, int st, int c, int a)
                  {

                  }

                  @Override
                  public void afterTextChanged(Editable s)
                  {
                  if(edittextbox1.getText().toString().length() != 0 && edittextbox2.getText().toString().length() != 0) {
                  textView.setVisibility(View.VISIBLE);
                  textview.setText("some text");
                  }
                  }
                  };

                  edittextbox1.addTextChangedListener(textWatcher);
                  edittextbox2.addTextChangedListener(textWatcher);






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 19 '18 at 9:47

























                  answered Nov 19 '18 at 9:39









                  Faysal AhmedFaysal Ahmed

                  3,64141230




                  3,64141230

























                      3














                      You need to use something like this to listen to your EditText fields.



                      edittextbox1 = (EditText)findViewById(R.id.editText);

                      edittextbox1.addTextChangedListener(new TextWatcher() {

                      @Override
                      public void onTextChanged(CharSequence s, int st, int b, int c)
                      {

                      }

                      @Override
                      public void beforeTextChanged(CharSequence s, int st, int c, int a)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }

                      @Override
                      public void afterTextChanged(Editable s)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }
                      });





                      share|improve this answer
























                      • Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?

                        – John
                        Nov 19 '18 at 9:39
















                      3














                      You need to use something like this to listen to your EditText fields.



                      edittextbox1 = (EditText)findViewById(R.id.editText);

                      edittextbox1.addTextChangedListener(new TextWatcher() {

                      @Override
                      public void onTextChanged(CharSequence s, int st, int b, int c)
                      {

                      }

                      @Override
                      public void beforeTextChanged(CharSequence s, int st, int c, int a)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }

                      @Override
                      public void afterTextChanged(Editable s)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }
                      });





                      share|improve this answer
























                      • Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?

                        – John
                        Nov 19 '18 at 9:39














                      3












                      3








                      3







                      You need to use something like this to listen to your EditText fields.



                      edittextbox1 = (EditText)findViewById(R.id.editText);

                      edittextbox1.addTextChangedListener(new TextWatcher() {

                      @Override
                      public void onTextChanged(CharSequence s, int st, int b, int c)
                      {

                      }

                      @Override
                      public void beforeTextChanged(CharSequence s, int st, int c, int a)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }

                      @Override
                      public void afterTextChanged(Editable s)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }
                      });





                      share|improve this answer













                      You need to use something like this to listen to your EditText fields.



                      edittextbox1 = (EditText)findViewById(R.id.editText);

                      edittextbox1.addTextChangedListener(new TextWatcher() {

                      @Override
                      public void onTextChanged(CharSequence s, int st, int b, int c)
                      {

                      }

                      @Override
                      public void beforeTextChanged(CharSequence s, int st, int c, int a)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }

                      @Override
                      public void afterTextChanged(Editable s)
                      {
                      if(edittextbox1.getText().toString().length() !=0) {
                      textview.setText("some text")
                      }
                      }
                      });






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 19 '18 at 9:32









                      JantzillaJantzilla

                      4451416




                      4451416













                      • Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?

                        – John
                        Nov 19 '18 at 9:39



















                      • Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?

                        – John
                        Nov 19 '18 at 9:39

















                      Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?

                      – John
                      Nov 19 '18 at 9:39





                      Thanks for the answer! Do you know if there is a easy way to look at both 'edittextbox1' og 'edittextbox2'?

                      – John
                      Nov 19 '18 at 9:39











                      0














                      pls try set visibility of your textview



                        @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                      savedInstanceState) {
                      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                      ...

                      if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
                      textview.setText("some text");
                      textview.setVisibility(View.VISIBLE);
                      }
                      return rootView;
                      }





                      share|improve this answer
























                      • this either won't work because he needs to listen to text changes

                        – Vladyslav Matviienko
                        Nov 19 '18 at 9:31
















                      0














                      pls try set visibility of your textview



                        @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                      savedInstanceState) {
                      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                      ...

                      if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
                      textview.setText("some text");
                      textview.setVisibility(View.VISIBLE);
                      }
                      return rootView;
                      }





                      share|improve this answer
























                      • this either won't work because he needs to listen to text changes

                        – Vladyslav Matviienko
                        Nov 19 '18 at 9:31














                      0












                      0








                      0







                      pls try set visibility of your textview



                        @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                      savedInstanceState) {
                      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                      ...

                      if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
                      textview.setText("some text");
                      textview.setVisibility(View.VISIBLE);
                      }
                      return rootView;
                      }





                      share|improve this answer













                      pls try set visibility of your textview



                        @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                      savedInstanceState) {
                      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                      ...

                      if(edittextbox1.getText().toString().length() !=0 && edittextbox2.getText().toString().length() !=0) {
                      textview.setText("some text");
                      textview.setVisibility(View.VISIBLE);
                      }
                      return rootView;
                      }






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 19 '18 at 9:27









                      ManishManish

                      4091620




                      4091620













                      • this either won't work because he needs to listen to text changes

                        – Vladyslav Matviienko
                        Nov 19 '18 at 9:31



















                      • this either won't work because he needs to listen to text changes

                        – Vladyslav Matviienko
                        Nov 19 '18 at 9:31

















                      this either won't work because he needs to listen to text changes

                      – Vladyslav Matviienko
                      Nov 19 '18 at 9:31





                      this either won't work because he needs to listen to text changes

                      – Vladyslav Matviienko
                      Nov 19 '18 at 9:31











                      -1














                      Do it like this. It will work!



                      @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                      savedInstanceState) {
                      View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                      EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
                      EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
                      TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);

                      if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
                      textView.setVisibility(View.VISIBLE);
                      textview.setText("some text");
                      } else {
                      textView.setVisibility(View.GONE);
                      }
                      return rootView;
                      }





                      share|improve this answer






























                        -1














                        Do it like this. It will work!



                        @Override
                        public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                        savedInstanceState) {
                        View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                        EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
                        EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
                        TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);

                        if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
                        textView.setVisibility(View.VISIBLE);
                        textview.setText("some text");
                        } else {
                        textView.setVisibility(View.GONE);
                        }
                        return rootView;
                        }





                        share|improve this answer




























                          -1












                          -1








                          -1







                          Do it like this. It will work!



                          @Override
                          public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                          savedInstanceState) {
                          View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                          EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
                          EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
                          TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);

                          if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
                          textView.setVisibility(View.VISIBLE);
                          textview.setText("some text");
                          } else {
                          textView.setVisibility(View.GONE);
                          }
                          return rootView;
                          }





                          share|improve this answer















                          Do it like this. It will work!



                          @Override
                          public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
                          savedInstanceState) {
                          View rootView = inflater.inflate(R.layout.text_to_speech, container, false);
                          EditText edittextbox1=(EditText)rootView.findViewById(R.id.your_edittext_id1);
                          EditText edittextbox2=(EditText)rootView.findViewById(R.id.your_edittext_id2);
                          TextView textView=(TextView)rootView.findViewById(R.id.your_textview_id1);

                          if ((edittextbox1.getText().toString().length() != 0) && (edittextbox2.getText().toString().length() != 0)) {
                          textView.setVisibility(View.VISIBLE);
                          textview.setText("some text");
                          } else {
                          textView.setVisibility(View.GONE);
                          }
                          return rootView;
                          }






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 19 '18 at 11:15









                          LordParsley

                          2,17611730




                          2,17611730










                          answered Nov 19 '18 at 9:36









                          Noorul HaarishaNoorul Haarisha

                          141




                          141






























                              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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371579%2fdisplay-textview-when-edittext-is-not-empty%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







                              Popular posts from this blog

                              How to pass form data using jquery Ajax to insert data in database?

                              National Museum of Racing and Hall of Fame

                              Guess what letter conforming each word