title: Android: Adding validation to EditText box?
body: <p>I need to add Validation to my EditText box so that:</p>
  
  <p>-Only numbers can be entered
  -An empty answer cannot be given (i.e. cannot just press enter button)</p>
  
  <p>If any of the above do happen, I just want the application to not accept the entry and allow the user to attempt to re-enter a valid entry.</p>
  
  <p>How can I do so?</p>
  
  <p><strong>Related activity code:</strong></p>
  
  <pre><code> answer = (EditText) findViewById(R.id.etEnterAnswerRandomTest);
  
       //when submit button is clicked
         public void onClick(View v) {
  
           switch(v.getId()) {
  
           case R.id.btnSubmitRandomTest:
              // sets string equal to what is entered in editText
              final String entry = answer.getText().toString();
              // convert from string value to int
              int a = Integer.parseInt(entry); 
  </code></pre>
  
  <p><strong>XML of edittext box:</strong></p>
  
  <pre><code>&lt;EditText
          android:id="@+id/etEnterAnswerRandomTest"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:ems="10"
          android:hint="Enter Answer..." &gt;
      &lt;/EditText&gt;
  </code></pre>