我对从 XML 文件中检索值以及如何有效地使用它没有明确的工作知识。有人可以帮我理解,怎么做?
这是我的文件和我的主要活动。我需要做的是,我将从设置中选择一个运算符,然后我将检查确切的运算符名称,并从名为 CallManager 的类中检索几个所需的字符串,并由另一个调用代码分段。我是为单个操作员做的,其中 preString 和内部数字大小是固定的。所以没问题。但我需要为其中几个做,从首选项中取名字。请帮助。谢谢-Piyal
<string-array name="operatormodes">
<item >Airtel</item>
<item >Banglalink</item>
<item >Grameen Phone</item>
<item >Robi</item>
<item >TeleTalk</item>
</string-array>
prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Operator
prefs.edit().putString(PreferencesActivity.KEY_OPERATOR_MODE, CaptureActivity.DEFAULT_OPERATOR_MODE).commit();
// Retrieve from preferences, and set in this Activity, the Operator mode
String[] operatorModes = getResources().getStringArray(R.array.operatormodes);
String operatorModeName = prefs.getString(PreferencesActivity.KEY_OPERATOR_MODE, operatorModes[0]);
Log.w("im changed", "Airtel");
if (operatorModeName.equals(operatorModes[0]))
{
callManager.setOperatorName("Airtel");
callManager.setOperatorBasedInternalDigit("Airtel");
callManager.setOperatorBasedInternalPreString("Airtel");
callManager.setPreString(callManager.internalPreString);
}
else if (operatorModeName.equals(operatorModes[1]))
{
callManager.setOperatorName("Banglalink");
callManager.setOperatorBasedInternalDigit("Banglalink");
callManager.setOperatorBasedInternalPreString("Banglalink");
callManager.setPreString(callManager.internalPreString);
}
else if (operatorModeName.equals(operatorModes[2]))
{
callManager.setOperatorName("Grameen Phone");
callManager.setOperatorBasedInternalDigit("Grameen Phone");
callManager.setOperatorBasedInternalPreString("Grameen Phone");
callManager.setPreString(callManager.internalPreString);
}
else if (operatorModeName.equals(operatorModes[3]))
{
callManager.setOperatorName("Robi");
callManager.setOperatorBasedInternalDigit("Robi");
callManager.setOperatorBasedInternalPreString("Robi");
callManager.setPreString(callManager.internalPreString);
}
else if (operatorModeName.equals(operatorModes[4]))
{
callManager.setOperatorName("TeleTalk");
callManager.setOperatorBasedInternalDigit("TeleTalk");
callManager.setOperatorBasedInternalPreString("TeleTalk");
callManager.setPreString(callManager.internalPreString);
}
prefs.registerOnSharedPreferenceChangeListener(listener);