簡體   English   中英

我無法使用sharedPreferences Android Studio獲得第一個字符串

[英]I can't get the first string using sharedPreferences android studio

我正在使用sharedpreferences,我可以將名稱放入.xml文件中,問題是當我嘗試僅獲取名字的ins時,這種情況下我可以看到: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]);

        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM