IF ステートメントを使用して、MobileNumber の値が 07 で始まるかどうかを確認しています。これが私のコードです。
public void MobileNumberCheck(EditText MobileNumber_Text, TextView ErrorDisplay, Boolean Output) {
Editable MobileNumber = MobileNumber_Text.getText();
Output = false;
///This method only has to check that the mobile number starts with 07, as the XML specifies the number can only be number, and 11 digits long.
if( (MobileNumber.charAt(0) != "0".charAt(0) ) || (MobileNumber.charAt(1) != "7".charAt(0)) ){
ErrorDisplay.setText("Invalid UK mobile number");
}
else if( (MobileNumber.charAt(0) == "0".charAt(0)) && (MobileNumber.charAt(1) == "7".charAt(0)) ){
///Do nothing
ErrorDisplay.setText("");
Output = true;
}
else
ErrorDisplay.setText(MobileNumber.charAt(0) + MobileNumber.charAt(1));
}
public void AddPeople_Save(View view){
TextView ErrorDisplay = (TextView) findViewById(R.id.AddPeople_ErrorDisplay);
EditText MobileNumber_ET = (EditText) findViewById(R.id.AddPeople_MobileNumber);
Boolean WriteReady = false;
MobileNumberCheck(MobileNumber_ET, ErrorDisplay, WriteReady); ///Runs the method specified above. Doesn't output, except into the TEXTVIEW ErrorDisplay.
EditText Name_ET = (EditText) findViewById(R.id.AddPeople_Name);
String AddPeople_PeopleFilename = "PartyApp_PeopleFile";
String Person_Details = Name_ET.toString() + MobileNumber_ET.toString();
FileOutputStream outputStream;
if(WriteReady == true)
try {
outputStream = openFileOutput(AddPeople_PeopleFilename, Context.MODE_PRIVATE);
outputStream.write(Person_Details.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
else{
///Do nothing. The error message is passed through METHOD MobileNumberCheck.
ErrorDisplay.setText("AAA" + WriteReady);
}
私が間違っていることを教えてもらえますか?? 論理演算子 && と || のいずれかを想定しています。が間違っているか、string.CharAt()
実装が間違っています。感謝!!