Retrieve an array from parse.com and add the values to a local array (Android)

泪湿孤枕 提交于 2019-12-07 06:32:08

问题


I have an array column called "Roots" in a user class from parse.com and I want to retrieve the array object from the column and then extract the values (strings) to an array in my application.

ParseUser.logInInBackground(user, password, new LogInCallback() {
                public void done(ParseUser user, ParseException e) {
                    if (user != null) {
                        // Hooray! The user is logged in.
                        startMenu();
                        String[] testStringArray = (String[])user.get("Roots");

I'm not sure if the last line even works. Even if it does, I'm not sure how to extract the individual elements and set them to a local array that I can call on using an index e.g.

String myString = testStringArray[1]

Or some such. I have tried a few variations of the above code and I think I am missing something fundamental. Does anyone have an example of how I can accomplish this? Thanks in advance!


回答1:


Use an ArrayList<String> instead of String[], then you can access it as you would any other ArrayList object.

ArrayList<String> testStringArrayList = (ArrayList<String>)user.get("Roots");
String myString = testStringArrayList.get(1);


来源:https://stackoverflow.com/questions/24590859/retrieve-an-array-from-parse-com-and-add-the-values-to-a-local-array-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!