android调用string—array

private Map initPreference() {

		SharedPreferences sp = getSharedPreferences(
				Constants.PREFERENCE_ARRAY_SMS, MODE_PRIVATE);

		int smsCount = sp.getInt(Constants.PREFERENCE_SMS_COUNT, 0);

		String[] templates = getResources().getStringArray(R.array.template);

		Map map = new HashMap();

		if (smsCount == 0) {

			Editor editor = sp.edit();

			for (int i = 0; i < templates.length; i++) {
				editor.putString(String.valueOf(i), templates[i]);
				SmsEntity entity = new SmsEntity();
				entity.setId(i);
				entity.setSms(templates[i]);
				map.put(i, entity);
			}
			editor.putInt(Constants.PREFERENCE_SMS_COUNT, templates.length);
			editor.commit();
		} else {
			for (int i = 0; i < smsCount; i++) {
				SmsEntity entity = new SmsEntity();
				entity.setId(i);
				entity.setSms(sp.getString(String.valueOf(i), ""));
				map.put(i, entity);
			}
		}

		return map;
	}


xml中;




    
        {name}你好,请提交周报说明本周工作进展及下周计划,特别说明发现的问题、需要协调支持等部分。项目负责人请提交项目周报。
        {name},岁末甫至,福气东来,鸿运通天。否极泰来时重申鲲鹏之志,惜时勤业中,展君无限风采。祝新年吉祥! 
    



你可能感兴趣的:(android调用string—array)