내 안드로이드 응용 프로그램에서 'IntEditTextPreference'라는 클래스를 사용하고 있습니다. 이 클래스는 사용자가 선호도를 정수로 사용하기를 원할 때 사용됩니다.NumberFormatException with IntEditTextPreference
하지만 문제가 있습니다. 사용자가 필드를 비워두고 "ok"를 누르면 NumberFormatException이 발생합니다.
필드가 비어있을 때 사용자가 "확인"을 누르지 않도록하려면 어떻게해야합니까?
감사합니다.
public class IntEditTextPreference extends EditTextPreference
{
public IntEditTextPreference(Context context)
{
super(context);
}
public IntEditTextPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public IntEditTextPreference(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
protected String getPersistedString(String defaultReturnValue)
{
return String.valueOf(getPersistedInt(-1));
}
@Override
protected boolean persistString(String value)
{
return persistInt(Integer.valueOf(value));
}
} 일반적으로
기본값은 – CocoNess
입니다. 여기서 persistInt 메소드는 무엇입니까? –