是否有可能在Android没有数据库存储? [英] Is it possible store without a database at android?

查看:153
本文介绍了是否有可能在Android没有数据库存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在应用程序中存储列表,而不必拥有数据库?
否则,存储简单列表的最简单方法是什么?

Is possible store a list within application, without necessarily having a database? Otherwise, what would be the easiest way to store a simple list?

推荐答案

我认为这取决于内容您正在处理的列表。如果List仅存储简单对象(如只有少数成员的整数或其他对象的字符串列表),则可以使用Android中内置的SharedPrefenrence。他们需要一把钥匙和一个价值。因此,如果你的List包含5个对象 - 让我们说点保持简单 - 你可以保存它们像

I think it depends on the contents of the list you are working on. If your List is storing "Simple-Objects" only (like List of String List of integer or other Objects with only a few members) you can use SharedPrefenrences which are build in in Android. They need a key and a value. So if your List contains 5 Objects of - lets say Points to keep it simple - you can save them like

SharedPreferences.Editor editor = getSharedPreferences("YourListName", MODE_PRIVATE).edit();
for(int i = 0; i < YOUR_LIST.count() ; i++){
    Point p = YOUR_LIST.get(i);
    editor.putInt("Element" + i + " X", p.x);
    editor.putInt("Element" + i + " Y", p.y);
}
editor.commit();

再次收到此消息你可以说

to recieve this again you could just say

SharedPreferences prefs = getSharedPreferences("YourListName", MODE_PRIVATE);
Map<String, ?> map = prefs.getAll();

这篇关于是否有可能在Android没有数据库存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆