Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.TextView.OnEditorActionListener;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final EditText text1 = (EditText) findViewById(R.id.text1);
- text1.setOnEditorActionListener(new OnEditorActionListener() {
- public boolean onEditorAction(TextView editText, int actionId, KeyEvent keyEvent) {
- if (Integer.valueOf(text1.getText().toString())>=50) {
- text1.setError("Must be less than 50");
- return true; //keeps this field in focus in case I had >1 entry fields
- }
- return false;
- }
- });
- }
- }
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <EditText
- android:id="@+id/text1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="number"/>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement