How to get item value from ArrayList in an Object - android

I am trying to process XML plist data from an API, but am hitting lots of walls!
The data is Apple plist format, which I am parsing using Akos' code from this link which seems to work perfectly. It is parsing as String, Object into a HashMap. I am able to get the value of a given key ie.
Object childItems = items.mPlistHashMap.get("childItems");
System.out.println(childItems.getClass());
System.out.println(childItems);
childItems.getClass() shows as - class java.util.ArrayList
The LogCat output for childItems shows -
[{remoteFilePath=/Picture.png, host=www.host.com, ratingCount=1, targetId=82, commentCount=1, externalId=/demo.host.com/Private/Picture.png, fileSize=23738, entity_name=Item, memberAccessLevel=0, leaderAccessLevel=0, name=Picture.png, target=SystemUser, ownerAccessLevel=3, tagCount=1}, {lastName=Test, entity_name=User, username=Test, host=www.host.com, userId=82, firstName=Test, password=TestPwd, loginName=Test}, {typeId=0, entity_name=UserType, name=UserType_Teacher}]
I presume that I can then work with this ArrayList, but this is where I am coming undone. For instance I want to get the remoteFilePath value, and display this in a ListView (already working for local files).
The example childItems list above only contain one file (Picture.png), but this list could contain any number of files, so I would need to iterate the list and get any values for remoteFilePath to display.
Any help appreciated, I just don't know how to "bore down" into this list, or if the childItems object needs to be cast to a new Array or so on.
If I'm missing any vital information, ask and I shall provide :)

ArrayList<?> childItems = (ArrayList<?>) elockeritems.mPlistHashMap.get("childItems");
I can now work with this. I need to get my head around the fundamentals!

Related

Get specific range of Firebase Database children

E.g. I have next data in my Firebase Realtime Database (my json file contains json array of some objects):
I would like to get all objects starting from a specific index (position) to the end of this array (in Firebase DB json array is converted to simple object which contains children with keys 001, 002 and so on)
So I need something like this but for Firebase query:
list.subList(10, list.size)
I know there are limitToFirst, limitToLast methods but it's different
fireDatabaseReference.child("episodes").limitToLast(10)
It won't do what I need. Because I need to know the size of this array and I need to be sure that this array won't become bigger at the moment someone makes such request (at some point this array can get become bigger due to adding new objects)
Would be great to have a method like from to get all children from 10 to the end (so first 9 children are excluded):
fireDatabaseReference.child("episodes").from(10)
But there is no such method
Is there any solution for this?
Solved :)
fireDatabaseReference.child("episodes").orderByKey().startAt("10")

Original array size and list.size returns different values

I was creating a RecyclerView in which the adapter gets items from a JSON file which I created in assets folder.I am using GSON to convert it to list of objects. while running the app was crashing because of Nullpointer Exception. while debugging I saw that the array size is not matching the original element count.Can anybody share their views on this?
I had to add list.size-1 in the getItemCount() instead of just adding list.size in order for my app to work.
in the screenshot at bottom of page the arry size is 8 and opened up array shows only 7 elements, which should never happen.
Okay, This is because of an extra comma after the last object in my JSON array which I tried to parse. While converting it to list of objects because of the comma GSON thinks there is one more object coming.Removed the comma and everything worked fine.seeing the array in debugging window makes no sense , got the app working but still didn't understand how it returned 8 for a 7 element array.
Found from Perception's Answer that size returns an instance variable.have to search in GSON source to know how it does the parsing

How would I go about displaying data from an API website and putting it in text format on an activity page?

I want to show data in a sensible form for my movie database app. The website I am using to extract data from is www.omdbapi.com. I have already created a code that extracts the title and year of the movies and displays it in a ListView form which contains items that are all clickable to another activity. I would like each activity that the ListView item clicks to to display the movie information under different headers etc.
I have been stuck on this issue all day. I'm new to coding and have no clue what most processes are called etc. Im not asking for the entire code, just instructions on what to do because I am stumped. I would be very very grateful.
Thank you.
Depending on the format the response is formatted you would either use (probably) an xml parser or a JSON parser and grab the info between specific xml tags or the specific keys within the JSON output.
There are thousands of examples of both methods. If you can get the title to display, then you already know how to get the other elements.

Get an arraylist from Parse.com in a new Activity

I wish to get an array from the Parse cloud. After tapping on an item in a list (which contains the ParseObject reference), the item will open a new activity and from this I want to get the array list stored in the latLngPoints key in Parse. I have googled and only found the following solution but it does not work:
ArrayList<ParseGeoPoint> parseList = (ArrayList<ParseGeoPoint>) getIntent().getExtras().getParcelableArrayList("latLngPoints");
Is it possible to even do it this way, or will I have to create a Parse object and create a request to get the information I need?
ParseObjects are not parcelable. You can pass an array list of longs that represent lat and long

ArrayList with Multiple data

I have a small issue with ArrayList. I have to fetch the document from the server.
The document contains 7 fields of data. I have to show the document names in the list view.
For this I have added different fields data to the different ArrayList. So when I click on the document name, based on the position of the document, I fetched the all fields data from the different Arraylist based on the position.
But Have a small issue using by using the above procedure. Is there any procedure that is not depend on the position, what I want is irrespective of position if I click on the Document,based on the keyword document data to be extract.
Any Help Appreciated.
Thanks in Advance.
I got your point. If you try to manage different ArrayLists then it would be difficult to manage it. I mean if you delete item from particular position from particular ArrayList then you will have to delete items from same position from other ArrayList, if you forgot to do so then it will be unbalanced.
Solution:
Instead feasible solution is to create ArrayList<Object> or ArrayList<HashMap<String,String>>, so your every item is the type of particular object, and every object contains detail and everything of particular items.
For example: ArrayList<Documents>, here ArrayList will contains list of Documents objects, and every objects contains values of 7 fields.
Its simply easy to define Documents class with getter/setter attributes.

Categories

Resources