Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3. import android.view.KeyEvent;
  4. import android.widget.EditText;
  5. import android.widget.TextView;
  6. import android.widget.TextView.OnEditorActionListener;
  7.  
  8. public class MainActivity extends Activity {
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. final EditText text1 = (EditText) findViewById(R.id.text1);
  15. text1.setOnEditorActionListener(new OnEditorActionListener() {
  16. public boolean onEditorAction(TextView editText, int actionId, KeyEvent keyEvent) {
  17. if (Integer.valueOf(text1.getText().toString())>=50) {
  18. text1.setError("Must be less than 50");
  19. return true; //keeps this field in focus in case I had >1 entry fields
  20. }
  21. return false;
  22. }
  23. });
  24. }
  25. }
  26.  
  27. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  28. xmlns:tools="http://schemas.android.com/tools"
  29. android:layout_width="match_parent"
  30. android:layout_height="match_parent"
  31. android:orientation="vertical" >
  32.  
  33. <EditText
  34. android:id="@+id/text1"
  35. android:layout_width="match_parent"
  36. android:layout_height="wrap_content"
  37. android:inputType="number"/>
  38. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement