尋找一些建議和幫助TextUtils setError()
消息顯示在錯誤的EditText中。我正在檢查EditText的所有內容,以確保它們不留空白,並且該部分正在工作,它只是指向第一個EditText字段,而不是正確的EditText字段,它留空,我想知道如何獲取它指向了正確的一個。我將所有標記爲EditText缺失的消息顯示在下面的屏幕截圖中,背景提示「輸入值...」爲空,這是自定義標籤指向的內容,但警告感嘆是一個完全不同的EditText字段。我該如何解決這個問題?我只是打電話給setError()
這樣的消息: someEditText.setError(custom message here)
。謝謝大家。TextUtils setError()顯示在錯誤的EditText字段
見setError()
截圖:
這裏是我使用的的EditText字段代碼。
/* Using the Pipe class setters to set the values collected from the editText fields. */
/*
Implementing the TextUtils.isEmpty() method for all text fields that are Strings in nature
to check for empty values. Surrounding all those EditText fields that capture doubles with
a try/catch and calling a custom Toast message for them to the user. All of the messages
state exactly which EditText field was left empty.
*/
newPipe.setJointId(etPipeId.getText().toString());
if (TextUtils.isEmpty((etPipeId.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+DISPLAY_PIPE_ID+" field");
return;
}
newPipe.setJointNum(etPipeJtNum.getText().toString());
if (TextUtils.isEmpty((etPipeJtNum.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+DISPLAY_PIPE_JT_NUM+" field");
return;
}
newPipe.setJointHeat(etPipeHeat.getText().toString());
if (TextUtils.isEmpty((etPipeHeat.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+DISPLAY_PIPE_HEAT+" field");
return;
}
try {
newPipe.setJointLength(parseDouble(etPipeLt.getText().toString()));
}catch (Exception e) {
Toast.makeText(getApplicationContext()
,EMPTY_VALUES+"\nPlease fill-in the "+DISPLAY_PIPE_LT+" field",
Toast.LENGTH_LONG).show();
return;
}
newPipe.setJointManufacturer(etPipeManufacturer.getText().toString());
if (TextUtils.isEmpty((etPipeManufacturer.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_JOINT_MANUFACTURER
+" field");
return;
}
try {
newPipe.setWallThickness(parseDouble(etPipeWallThick.getText().toString()));
}catch (Exception e) {
Toast.makeText(getApplicationContext()
,EMPTY_VALUES+"\nPlease fill-in the "+DISPLAY_JOINT_WALL_THICKNESS+" field",
Toast.LENGTH_LONG).show();
return;
}
newPipe.setGrade(etPipeGrade.getText().toString());
if (TextUtils.isEmpty((etPipeGrade.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_GRADE
+" field");
return;
}
newPipe.setCoatingType(etPipeCoatType.getText().toString());
if (TextUtils.isEmpty((etPipeCoatType.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_JOINT_COAT_TYPE
+" field");
return;
}
newPipe.setCoatingThick(etPipeCoatThick.getText().toString());
if (TextUtils.isEmpty((etPipeCoatThick.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_JOINT_COAT_THICKNESS
+" field");
return;
}
try {
newPipe.setSizeDiameter(parseDouble(etPipeSizeDiameter.getText().toString()));
}catch (Exception e) {
Toast.makeText(getApplicationContext()
,EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_JOINT_DIAMETER +" field",
Toast.LENGTH_LONG).show();
return;
}
newPipe.setCurrentLocation(etPipeLocation.getText().toString());
if (TextUtils.isEmpty((etPipeLocation.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_CURRENT_LOCATION
+" field");
return;
}
try {
newPipe.setCuts(parseDouble(etPipeCuts.getText().toString()));
}catch (Exception e) {
Toast.makeText(getApplicationContext()
,EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_CUTS +" field",
Toast.LENGTH_LONG).show();
return;
}
try {
newPipe.setNewLength(parseDouble(etPipeNewLt.getText().toString()));
}catch (Exception e) {
Toast.makeText(getApplicationContext()
,EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_NEW_LT +" field",
Toast.LENGTH_LONG).show();
return;
}
newPipe.setChildJointId(etPipePup.getText().toString());
if (TextUtils.isEmpty((etPipePup.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_CHILD_JT_ID
+" field");
return;
}
newPipe.setNotes(etPipeNotes.getText().toString());
if (TextUtils.isEmpty((etPipeNotes.getText().toString()))) {
etPipeId.setError(EMPTY_VALUES+"\nPlease fill-in the "+ DISPLAY_NOTES
+" field");
return;
}
/* Inserting the collected data from above into the insertPipe() method*/
if (dbHelper != null) {
dbHelper.insertPipe(newPipe);
}
finish();
if (dbHelper != null) {
dbHelper.close(); /* closing the database down here to prevent resource leaks.*/
}
} /* savePipe method ends here. */
您可以加入一些代碼也許問題是有 –