我是新的Android。我正在與Json共享偏好。從JSON我得到的數據並保存到共享偏好,它工作正常。我想將SharedPreferences中的共享首選項數組數據分配給字符串。共享偏好陣列數據emtpty數組保存在android系統
這是代碼:
private ArrayList<String>urls2 = new ArrayList<>();
private ArrayList<String>urls1 = new ArrayList<>();
this is the json parse
if (errorCode == 0) {
email = p.getString("email");
firstName = p.getString("firstName");
lastName = p.getString("lastName");
phone = p.getString("phone");
status = p.getString("status");
updatedDate = p.getString("updatedDate");
serverURL = p.getString("url");
urls1.add(p.getString("url"));
// urls1.append(",");
Log.d("URL", "" + urls1);
urls2.add(p.getString("staffId")) urls2.append(",");
Log.d("STAFFID", "" + urls2);
}
SharedPreferences:
SharedPreferences.Editor editor = getSharedPreferences("LOGINACTIVITY", 0).edit();
for(int i=0;i<urls2.size();i++) {
editor.putString("staffId1" + i, urls2.get(i));
Log.d("staffId1",urls2.get(i).toString());
}
for(int i=0;i<urls1.size();i++) {
editor.putString("serverURL" + i, urls1.get(i));
Log.d("SavedURl",urls1.get(i).toString());
}
in next view controller i want assing the shared preference array data string
like ex : firsturl = arrayshared[0]
secondurl = arrayshared[1]
this is next view controller
ArrayList<String> staffdata = new ArrayList<String>();
int listsize = mPrefsManager.getInt("staffId1", 0);
Log.d("firstcall of<<<<<<<",""+listsize);
for(int i=0; i<=listsize; i++) {
if(listsize == 0)
{
Hear : first shared preference array first element data
like ex : firsturl = arrayshared[0]
Log.d("firstcall of<<<<<<<",""+listsize);
firsturl = .get(i).toString()
}
else
{
like : secondurl = arrayshared[1]
===> hear second url data
Log.d("second irst<<<",""+listsize);
}
如何從共享偏好數組中的數據到達串
你忘了加上'editor.commit( );'沒有提交它不會保存任何數據 –
我這樣做,但我的問題是sharedpreference陣列數據串 –
「請幫助我」你需要超過13歲才能在本網站參與。如果你是,像這樣行動 –