title: Android - How to check if EditText is empty and disable Button?
body: <p>I'm working on an Android app, most of it was with the help of tutorials and reading material, my app is somewhat basic, make some calculations and display the result to the user</p>
  
  <p><strong>What I have</strong></p>
  
  <p>I created a fragment guided by <a href="http://haidermushtaq.com/tutorial-for-creating-android-swiping-application-using-tabbed-activity-on-android-studio/" rel="nofollow noreferrer">this tutorial</a> and I just replaced the button and textview with my own EditText and Button</p>
  
  <p>I have an EditText, a Button, and a TextView, these are the widgets the user see when the fragment is opened</p>
  
  <p><strong>My goal</strong></p>
  
  <p>I want the user to input values in the EditText and when s/he click the button the TextView displays the result of some calculations</p>
  
  <p><strong>What I did</strong></p>
  
  <p>I've been trying some other answers from <a href="https://stackoverflow.com/questions/21777576/how-to-make-a-button-unclickable-if-edittext-is-empty">here</a>, <a href="https://stackoverflow.com/questions/24391809/android-check-if-edittext-is-empty">here</a>, <a href="https://stackoverflow.com/questions/27876677/check-if-edittext-is-empty-that-only-accepts-numbers">here</a>, <a href="https://stackoverflow.com/questions/22680106/how-to-disable-button-if-edittext-is-empty">here</a>, but I don't know how to wire up the code, every time I write some pieces of code my app crashes and I don't know what else to do</p>
  
  <p>Here is my code</p>
  
  <pre><code>public class Circle_Perimeter extends Fragment
  {
      EditText edtxt;
      Button btn;
      TextView txt;
  
      public static Circle_Perimeter newInstance()
      {
          Circle_Perimeter fragment = new Circle_Perimeter();
          return fragment;
      }
  
      public Circle_Perimeter()
      {
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater,
                               ViewGroup container,
                               Bundle savedInstanceState)
      {
          View rootView = inflater.inflate(R.layout.fragment_circle__perimeter,container,false);
  
          edtxt = (EditText)rootView.findViewById(R.id.editText);
          btn = (Button)rootView.findViewById(R.id.button6);
          txt = (TextView) rootView.findViewById(R.id.textView6);
  
          btn.setOnClickListener(new View.OnClickListener()
          {
              @Override
              public void onClick(View view)
              {
  
              }
          });
  
          return rootView;
      }
  }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>How and where do I write the necessary code to make the EditText send a Toast warning the user the EditText is empty? or disable the Button if the EditText is empty?</p>
  
  <p>EDIT: Really?? A downvote?? Instead of downvoting... Just give a warning or something else</p>
  
  <p>EDIT 2: I already said that I did follow another answers from <a href="https://stackoverflow.com/questions/22680106/how-to-disable-button-if-edittext-is-empty">here</a> and I couldn't make my code work that's why I'm here looking for an answer WITH my piece of code</p>