Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6199329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:10:12+00:00 2026-05-24T04:10:12+00:00

My application has several EditText boxes, and when the done button is pressed I

  • 0

My application has several EditText boxes, and when the “done” button is pressed I validate the input and return the activity result. The problem is that when I try to read the data it is null, and I can’t figure out why.

Here’s my code:

public class CreatePlayer extends Activity implements OnItemSelectedListener {

private EditText textFirstName;
private EditText textLastName;
private EditText jerseyNumber;
private Spinner spinner;

private int arrayID;

private boolean validFirstName = false;
private boolean validLastName = false;
private boolean validJerseyNumber = false;
private boolean validPosition = false;

private static final String TAG = "CreatePlayer";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.createplayer);

    final EditText textFirstName = (EditText) findViewById(R.id.playername_first_edit);
    EditText textLastName = (EditText) findViewById(R.id.playername_last_edit);
    final EditText jerseyNumber = (EditText) findViewById(R.id.playernum_edit);

    arrayID = getIntent().getExtras().getInt("arrayID");
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, arrayID, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    textFirstName
            .setOnEditorActionListener(new EditText.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,
                        KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {

                        boolean result = v
                                .getText()
                                .toString()
                                .matches(
                                        getString(R.string.regex_first_name));

                        System.out.println(v.getText());
                        System.out.println(result);
                        Pattern p = Pattern
                                .compile(getString(R.string.regex_first_name));
                        Matcher m = p.matcher(v.getText());
                        Log.v(TAG, "pattern=" + p.toString());
                        Log.v(TAG, "text=" + v.getText());
                        Log.v(TAG, "result=" + result);
                        Log.v(TAG, "find=" + m.find());

                        if (result) {
                            validFirstName = true;
                            //textFirstName = (EditText) v.getText();
                        }

                    }
                    return false;
                }
            });
    textLastName
            .setOnEditorActionListener(new EditText.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,
                        KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {
                        boolean result = v
                                .getText()
                                .toString()
                                .matches(
                                        getString(R.string.regex_last_name));
                        Pattern p = Pattern
                                .compile(getString(R.string.regex_last_name));
                        Matcher m = p.matcher(v.getText());
                        Log.v(TAG, "pattern=" + p.toString());
                        Log.v(TAG, "text=" + v.getText());
                        Log.v(TAG, "result=" + result);
                        Log.v(TAG, "find=" + m.find());

                        if (result) {
                            validLastName = true;
                        }
                    }
                    return false;
                }
            });
    jerseyNumber
            .setOnEditorActionListener(new EditText.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,
                        KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {

                        Pattern p = Pattern
                                .compile(getString(R.string.regex_jerseynum));
                        boolean result = v
                                .getText()
                                .toString()
                                .matches(
                                        getString(R.string.regex_jerseynum));
                        Matcher m = p.matcher(v.getText());
                        Log.v(TAG, "pattern=" + p.toString());
                        Log.v(TAG, "text=" + v.getText());
                        Log.v(TAG, "result=" + result);
                        Log.v(TAG, "find=" + m.find());

                        if (result) {
                            validJerseyNumber = true;
                        }
                    }
                    return false;
                }
            });
}

public void okClicked(View v) {

    PlayerInfo newPlayer;

    if (validFirstName && validLastName && validJerseyNumber
            && validPosition) {
        Log.v(TAG, "JerseyNumber = " + jerseyNumber);
        // jerseyNumber is null???
        int num = Integer.parseInt(jerseyNumber.getText().toString());
        String type = spinner.getSelectedItem().toString();
        Log.v(TAG, "type = " + type);
        String name = textFirstName.getText().toString() + " "
                + textLastName.getText().toString();
        newPlayer = new PlayerInfo(BaseBoard.playerIDCounter, num, type,
                name);
        Intent result = new Intent();
        result.putExtra(getString(R.string.players_create), newPlayer);
        setResult(5, result);
        this.finish();
    } else {
        Toast toast = Toast.makeText(getApplicationContext(),
                "Invalid input. Try something like John Smith, #27, PG",
                Toast.LENGTH_SHORT);
        toast.show();
    }
}

public void cancelClicked(View v) {
    this.setResult(-1, null);
    this.finish();
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,
        long id) {
    validPosition = true;
    System.out.println(parent.getItemAtPosition(pos).toString());
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:10:12+00:00Added an answer on May 24, 2026 at 4:10 am

    I was obscuring the member. This works:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newcreateplayer);
    
        textFirstName = (EditText) findViewById(R.id.playername_first_edit);
        textLastName = (EditText) findViewById(R.id.playername_last_edit);
        jerseyNumber = (EditText) findViewById(R.id.playernum_edit);
    
        arrayID = getIntent().getExtras().getInt("arrayID");
        spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, arrayID, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);
    
        textFirstName
                .setOnEditorActionListener(new EditText.OnEditorActionListener() {
                    //@Override
                    public boolean onEditorAction(TextView v, int actionId,
                            KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_NEXT) {
    
                            boolean result = v
                                    .getText()
                                    .toString()
                                    .matches(
                                            getString(R.string.regex_first_name));
                            Pattern p = Pattern
                                    .compile(getString(R.string.regex_first_name));
                            Matcher m = p.matcher(v.getText());
                            Log.d(TAG, "pattern=" + p.toString());
                            Log.d(TAG, "text=" + v.getText());
                            Log.d(TAG, "result=" + result);
                            Log.d(TAG, "find=" + m.find());
    
                            if (result) {
                                validFirstName = true;
                            }
    
                        }
                        return false;
                    }
                });
        textLastName
                .setOnEditorActionListener(new EditText.OnEditorActionListener() {
                    //@Override
                    public boolean onEditorAction(TextView v, int actionId,
                            KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_NEXT) {
                            boolean result = v
                                    .getText()
                                    .toString()
                                    .matches(
                                            getString(R.string.regex_last_name));
                            Pattern p = Pattern
                                    .compile(getString(R.string.regex_last_name));
                            Matcher m = p.matcher(v.getText());
                            Log.d(TAG, "pattern=" + p.toString());
                            Log.d(TAG, "text=" + v.getText());
                            Log.d(TAG, "result=" + result);
                            Log.d(TAG, "find=" + m.find());
    
                            if (result) {
                                validLastName = true;
                            }
                        }
                        return false;
                    }
                });
        jerseyNumber
                .setOnEditorActionListener(new EditText.OnEditorActionListener() {
                    //@Override
                    public boolean onEditorAction(TextView v, int actionId,
                            KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
    
                            Pattern p = Pattern
                                    .compile(getString(R.string.regex_jerseynum));
                            boolean result = v
                                    .getText()
                                    .toString()
                                    .matches(
                                            getString(R.string.regex_jerseynum));
                            Matcher m = p.matcher(v.getText());
                            Log.d(TAG, "pattern=" + p.toString());
                            Log.d(TAG, "text=" + v.getText());
                            Log.d(TAG, "result=" + result);
                            Log.d(TAG, "find=" + m.find());
    
                            if (result) {
                                validJerseyNumber = true;
                            }
                        }
                        return false;
                    }
                });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application that has several checkboxes, a submit button, and a
My iPhone application has several views and some viewControllers for that views. I need
I have an application that has several objects (about 50 so far, but growing).
I have a Silverlight 4 out-of-browser application with a ScrollViewer that has several RichTextBoxes
In my application I have several activities, the main screen has 4 buttons that
I'm building an application that is used by several different customers. Each customer has
I have an application that has several stores , and each store has several
So I have an application that has several modules (think of modules as different
I'm working on an Android application that has several Activities. In it I have
I have a Java Web application that has several servlets with the following mappings.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.