我正在使用共享首选项,我可以将名称放入 .xml 文件中,问题是当我尝试仅获取名字时 在这种情况下我可以看到: D/mySharedPref: [alan, lyneth, daniel, oscar] 但我只想看到 alan 我怎样才能得到我要问的名字
String id = "1";
for(int i = 0; i<getListValueFromKey.size(); i++){
Log.d("mySharedPref", ""+getListValueFromKey);
//in the log window show this:
// D/mySharedPref: [alan, lyneth, daniel, oscar]
}
最佳答案
好的,这就是我解决问题的方法:
//add to an Array
Object[] resourceArray = getListValueFromKey.toArray();
//I preferred to leave this var outside to manipulate after
int i;
//I put in the log the first name
Log.d("myName", ""+resourceArray[1]);
//I log the names inside the array
for(i = 0; i<resourceArray.length; i++){
Log.d("mySharedPref", ""+resourceArray[i]);
}
关于java - 我无法使用sharedPreferences android studio 获取第一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57530776/