public void getScore(View view){ // edittextを取得 EditText fEditText = (EditText) findViewById(R.id.firstnEditText); EditText lEditText = (EditText) findViewById(R.id.lastnEditText); EditText pEditText = (EditText) findViewById(R.id.phoneEditText); EditText mEditText = (EditText) findViewById(R.id.mailEditText); // edittextの中身を取得 String firstName = fEditText.getText().toString().trim(); String lastName = lEditText.getText().toString().trim(); String myPhone = pEditText.getText().toString().trim(); String myMail = mEditText.getText().toString().trim(); Pattern p = Pattern.compile("^[0-9\\-]+"); Matcher m = p.matcher(myPhone); Pattern mp = Pattern.compile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"); Matcher mm = mp.matcher(myMail); // 中身を観て条件分岐 if (firstName.equals("")){ fEditText.setError("Please enter your first name!"); } else if(lastName.equals("")){ lEditText.setError("Please enter your last name!"); } else if(myPhone.equals("") || m.find() == false){ pEditText.setError("Please enter your phone number!"); }else if(myMail.equals("") || mm.find() == false){ mEditText.setError("Please enter your valid email"); } else { Intent intent = new Intent(this, MyResult.class); intent.putExtra(EXTRA_MYFNAME, firstName); intent.putExtra(EXTRA_MYLNAME, lastName); intent.putExtra(EXTRA_MYPHONE, myPhone); intent.putExtra(EXTRA_MYMAIL, myMail); startActivity(intent); } }
入力すると
引き継がれる! EditTextは良さそうですね。