내가 값의 휴대폰 번호가 07이 시작 있는지 확인하는 IF 문을 사용하고 내 코드도 예상 :하면 String.charAt()가 반환하지 않습니다 값은
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()
이 잘못 구현되었습니다. 감사!!
_string.CharAt()가 잘못 구현되었습니다. ... 정말 그렇게 생각합니까? –
약간의 입력과 예상 출력 및 전류 출력을주세요. –
잘못 구현되었다고 생각하지 않았지만 통과하지 못했다고 생각했습니다. 그 점은 확실하지 않았습니다. "07"이외의 문자로 시작하는 전화 번호를 입력하면 파일에 기록되는 것을 멈추고 ErrorDisplay에 메시지를 표시해야합니다. –