嗨我正在制作一个显示游戏中4名玩家得分的记分卡,并且当用户按下按钮时,会插入一个新行。我这样做的:Android SharedPreference
private void makeTag(String P1Score, String P2Score, String P3Score, String P4Score, String slot)
{
// originalQuery will be null if we're modifying an existing search
String originalScore = SavedSlots.getString(slot, null);
// get a SharedPreferences.Editor to store new slot/scores
SharedPreferences.Editor preferencesEditor = SavedSlots.edit();
preferencesEditor.putString(slot, P1Score, P2Score, P3Score, P4Score); // to store
preferencesEditor.apply(); // store the updated preferences
然后,它提示了错误putString
下称:
The method putString(String, String) in the type SharedPreferences.Editor is not
applicable for the arguments (String, String, String, String, String).
似乎只能在同一时间商店2个变量? (即槽和P1Score)。
有4名球员,我想保存他们各自的分数,我该怎么做?
非常感谢您的帮助!但我的想法是,插槽数是游戏的整数,这意味着在插槽1中有P1,P2,P3和P4分数,然后当插槽2时,有另一组4个玩家得分。如果使用上面的slot1,slot2,slot3和slot4,它会把这个槽弄乱成Key。或者我的意思是使用4套sharedpreference(每个玩家一个),然后为每个玩家保存每一轮?因为一开始我希望能够使用1个键同时存储4个玩家的数据 – pearmak