Mr_en 2016-01-06 02:06 采纳率: 10%
浏览 1335
已采纳

关于android SharedPreference的问题,在线等!谢谢!!!

SharedPreferences 有没有办法根据vlaue获取对应的key值,除了循环SharePreferences里面的内容。

  • 写回答

4条回答 默认 最新

  • tony4geek 2016-01-06 02:14
    关注

    You should note that while keys are guaranteed to be unique in SharedPreferences, there's no guarantee that the values will be unique. As such, this function will only return the key for the first matching value.

     String findKey(SharedPreferences sharedPreferences, String value) {
        for (Map.Entry<String, ?> entry: sharedPreferences.getAll()) {
            if (value.equals(entry.getValue())) {
                return entry.getKey();
            }
        }
        return null; // not found
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败