将ArrayList与sharedpreferences一起使用。

时间:2014-02-16 16:52:37

标签: android sharedpreferences

我试图将ArrayList中的值存储到SharedPreferences并在另一个类中访问它们。这是我到目前为止所尝试过的。

public class sample {

final static String file = "myFile";
SharedPreferences fileName;

protected void onCreate(Bundle savedInstanceState) {

            Sharedpreferences.Editor list = SharedPreferences.edit();
            list.putStringArray("key", 0);
            list.commit();

    }
}

public class sample2 {

String array[] = {"can", "you", "help", "me", "with", "this?"};

protected void onCreate(Bundle savedInstanceState) {

         Random random = new Random();
         int x;
         x = random.nextInt(5);

         String generatedValue = arr[x];

         String get = fileName.getString("key", 0);
         SharedPreference.Editor editList = SharedPreferences.edit();
         editList.putString("key", get);
         editList.commit();
         }
}

任何帮助都将不胜感激。

0 个答案:

没有答案