내 응용 프로그램에서 EditText와 함께 AlertDialog를 사용하고 있습니다. 몇 번 호출했기 때문에이 코드를 메서드로 옮기고 싶습니다.메서드에서 EditText가있는 AlertDialog : 로컬 변수 editText가 초기화되지 않았을 수 있습니다.
private EditText showEditAlert(DialogInterface.OnClickListener listener) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(R.string.waypoint);
alert.setMessage(R.string.waypoint_alert_text);
EditText editText = new EditText(this);
alert.setView(editText);
alert.setPositiveButton(android.R.string.ok, listener);
alert.setNegativeButton(android.R.string.cancel, null);
alert.show();
return editText;
}
을 그리고 나는 그것을 사용하려면 : :이 방법으로 그것을 구현하려고
final EditText editText = showEditAlert(new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Here is I am working with editText
// and here is I get error "The local variable editText may not have been initialized"
}
});
하지만 "지역 변수 EDITTEXT가 초기화되지 않았을 수 있습니다"오류가 발생합니다. 컴파일러는 showEditAlert()가 value를 반환하기 전에 onClick() 메서드가 호출 될 것이라고 생각합니다.
올바르게 구현하는 방법은 무엇입니까? 아니면 그냥이 오류를 억제 할 수 있습니까?
가 오류가 나 편집자에 의해 주어진 경고? – amd
@ amd, 즉 편집기 (Eclipse)에서 제공 한 오류입니다. – BArtWell