比較的EditText值當我在EditText上輸入一個值,我不能把它與我的SharedPreference一個值進行比較。不能與SharedPreference價值
這是我的EditText偏好
<EditTextPreference
android:defaultValue="1234"
android:inputType="number"
android:key="userid"
android:maxLength="4"
android:singleLine="true"
android:summary="To Access App setting set a PIN"
android:title="Set PIN" />
這是我的了Methode代碼:
private void GoToSettings(){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
String userpin = prefs.getString("userid", "");
String userpin1 = txtpin.getText().toString();
if(userpin.equals(userpin1)){
/*Intent intent = new Intent(FingerprintScannerActivity.this, PreferencesActivity.class);
startActivity(intent);*/
Toast.makeText(getApplicationContext(),
"Good",
Toast.LENGTH_SHORT).show();
}else Toast.makeText(getApplicationContext(),
"Error PIN",
Toast.LENGTH_SHORT).show();
}
解決:我忘記加載PreferenceManager.setDefaultValues(this,R.xml.preferences_xml,false); –