在我的Android应用程序,我使用了一个名为“IntEditTextPreference”类。当我希望用户将首选项作为整数引入时,将使用此类。NumberFormatException异常与IntEditTextPreference
但它有一个问题。当用户将该字段留空并按下“ok”时,会引发NumberFormatException。
什么我可以做,以避免用户按“OK”时,该字段为空?
谢谢!
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方法? –