English 中文(简体)
如何利用共同的偏好储存整个数据
原标题:How to store array of data as a whole using shared preferences

我有一系列的体力、面积100。 我已输入这一阵列中的数据。 现在,我想用<条码”储存这种阵列。 共有项目

So my question is that, is it possible to store the entire array of string instead of storing each string individually using SharedPreferences. If so, how that can be done.

The code I have written is used to store data individually using the loop. But I want to store the entire string array without using the loop.

Code I have written for storing individually is

SharedPreferences preferencesWrite  = c.getSharedPreferences("myPreferences", 0);
SharedPreferences.Editor editor  = preferencesWrite.edit();

for(int i=0; i< 100; i++)
{
    editor.putString("dtHistory" + Integer.toString(i), m_dtHistory[i];

}
editor.commit();
问题回答

共享优惠只允许每个入境点节省单一物品——这一限制得到实施,使用户只能按照名称所示,储存“优惠”——旗帜、插图、编号等等。 这样做是为了消除不必要地使用三维物品的qlite数据库。

然而,有一种新的共享方法。 优惠(API 11)允许你储存一套插图。 http://developer.android.com/vis/android/content/jointPviss.Editor.html#putStringSet%28java.lang.String,%20java.util.Set%3Cjava.lang.String%3E%29"rel=“nofollow”

Yes it,s Possible to Store array in form of String

你们应当这样做:

    SharedPreferences preferencesWrite  = c.getSharedPreferences("myPreferences", 0);
    SharedPreferences.Editor editor  = preferencesWrite.edit();

     Gson gson = new Gson();
     ArrayList<ModelClass>favorites = new ArrayList<>();

     String jsonFavorites = gson.toJson(favorites);
     editor.putString("your sharedPref NTT", jsonFavorites);
     editor.apply();




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签