EditTextに値を入力すると、My SharedPreferenceの値と比較することができません。EditText値と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をロードすることを忘れて(これは、R.xml.preferences_xml、false); –