我已经定义了我的设置活动的布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceCategory 
    android:title="Second Category"
    android:key="second_category">
    <EditTextPreference
        android:id="@+id/pcnSetting"
        android:key="pcn"
        android:title="Set Canton Digits" 
        android:summary="Define your canton digits"
        android:dialogTitle="Set Canton Digits"
        android:dialogMessage="Please add your canton digits"
        android:inputType="number"
        android:imeOptions="actionDone"
        android:maxLength="4"/>
</PreferenceCategory>
我想将其导入EditTextPreference到我的 java 代码中,以确保用户输入至少和最多 4 位数字。
这就是我尝试EditTextPreference进入java的方式
    canton = (EditTextPreference)findViewById(R.id.pcnSetting); 
但是Eclipse给了我这个错误:
Cannot cast from View to EditTextPreference
为什么会这样?以及如何检查用户是否输入了至少和最大4 int's?