title: Android EditText Decimal Integer Value
body: <p>I have the following app that has a textview and an edittext. When the value of the edittext changes, it updates a textview's content. Now I want the value to be received as an integer. this is the current app:<br /></p>
  
  <pre><code>package your.test.two;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class TesttwoActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      EditText input = (EditText)findViewById(R.id.editText1);
      input.addTextChangedListener(new TextWatcher(){
          public void afterTextChanged(Editable s){
              update();
          }
          public void beforeTextChanged(CharSequence s, int start, int count, int after){}
          public void onTextChanged(CharSequence s, int start, int before, int count){}
      });
  }
  
  public void update(){
      EditText source = (EditText)findViewById(R.id.editText1);
      Editable sourceData = source.getText();
      TextView destination = (TextView)findViewById(R.id.textView1);
      destination.setText(sourceData);
  }
  }
  </code></pre>
  
  <p><br />
  Now I want the sourceData editable to be somehow converted to an integer so that I can do a if statement on it as follows:<br /></p>
  
  <pre><code>if(sourceData&gt;255){
    sourceData = 0;
  }
  </code></pre>
  
  <p>I already changed the values of the edittext in main.xml by adding the following lines to editText1:</p>
  
  <pre><code>android:inputType="number"
  android:maxLength="3"
  android:numeric="integer"
  </code></pre>
  
  <p>Could someone give me a few guidelines as to how this can be done please. Been googling it but all I end up with is things like:</p>
  
  <pre><code>Integer i = Integer.parseInt(edittext.gettext().tostring());
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>Integer i = Integer.valueOf(String s);
  </code></pre>
  
  <p>And I don't quite get those to work or understand it. Please help!? :(</p>