String Resources or JSON to populate SQLite Database on application start? - android

Currently, I have three string-arrays in my String Resources that hold information I need for the application to start and function. These arrays need to be kept in order as string-array A position 5 corresponds to string-array B position 5 and so on.
This doesn't seem great as it can be error prone and not extensible if I want to add 100 new datapoints - so I have been looking into using a JSON file to store the data which seems to be better.
My problem: I have a Recycler View that is populated with data from my String Resources. Each item in the Recycler View is different, so the first view will take information from the first entry in string-array A, B and C and continue through each view in the Recycler View.
Is it better to create a JSON file that collects and groups the data so corresponding data is kept together? As well as reading this file into my SQLite database and create a cursor object that will populate my Recycler View and allow for some other database related activities later on in my application? From what I can tell it is.
Is this a viable solution to my problem?
Thanks

Related

How to store a small list, on Android? SharedPreferences VS SQLite VS file

I have an app that generates objects of a class, let's call it X, that is Serializable. I want the user to be able to occasionally save or delete objects of X from his/her list of favorites (a list that can go up to 100 objects).
What is the most appropriate way to persistently store the list of favorites?
In SharedPreferences, storing the whole list as a JSON String
In an SQLite database:-
Storing one item per object, as BLOB's
Storing one item per object, as JSON Strings
In a custom file, storing the whole list as a JSON String
Some other way?
My thoughts are:
Because adding and removing favorites will be occasional, and the list is small, I probably don't need the advantages of a DB when it comes to searching fields in large amounts of data. So I am inclined to maintain a local ArrayList, add and remove items from it, and save it to SharedPreferences (option 1).
It seems odd to save a key-value pair holding an entire list as a JSON String, I'm afraid I might be unaware of some sort of limitation.
Is there a limit to the size of the String I can store in SharedPrefferences?
Is it too problematic that I add or remove objects from my local ArrayList and then save the whole list?
I am agree with your first approach because of It's manage easily and need small storage space.

how to use a list item to call and display a string in another fragment

i am a novice in android and i was trying to make an application that has two fragments, one with a listView with topics which when one is clicked it opens a topic description in the other fragment. i would like to know how to also store the large string for the description
If the data is dynamic you can store your topics and desciptions in a sqlite database. You have several possibilities:
You load the topic and description at the start and give over the description with a method or an interface to the second fragment.
You store the data in a database and give every entry a unique id and use a method or an interface to communicate with the second fragment and put the id to it. And then you use the id to get the description from database.
UPDATE #1
You can use arrays in your resource files. Create two arrays. One with your topics and the other with your descriptions. But the topics and descriptions have to be in the same order. For example the description of the second topic have to be on the second position in its array. Now you use the first array for your listview and the second(with the descriptions) in the description fragment. The "setOnItemClickListener" method of the listview have the position as a parameter. This is the same as the position of the topics and desciption in your arrays (when you dont resort anything).

How to distinguish between clicked and non-clicked item in ListView in Android

I have a scenario here.I am developing a housing app in which the Complex owners can post announcements and flat owners can see it.I am using webservice.The complex owner can add a new announcement(which I am saving in my server) and the flat owners can see those announcements(I am binding the announcements headers into a list view through json parsing and on-clicking a header a full message will be displayed).
Now the problem is in case of new announcements.I want to distinguish between the readed and unreaded messages(just like in our mail).So how can I determine which listview item is clicked or which item is not clicked??And also how can I give them different colors(i.e. to mark an item unreaded or not clicked ??)
Any help will be appreciated.
Save all announcements in a table locally in sqlite. Add a column to contain the read unread flag.
While populating the list read from the table and load considering the flag.

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.

GPS data -> MySQL -> Android sorted ListView

I'm programming an Android app that shows data from MySQL database via ListView with some sorting:
1) Items that are closer to android phone by GPS are shown firstly
If there are 2 or more items with equal distance, second sorting parameter applies - time.
2) Items that are closer in time are showm firstly.
Here is a scheme of the process that I guess to implement:
My idea is to get all needed rows into Array, then make some PHP manipulations with it and then pull sorted Array to the phone.
(as shown on the image above)
So please advice me what will be the proper way?
Maybe there is easier method for this functionality?
Or maybe I should do all the sortings exactly in the Android app when programming ListView, getting only standard "SELECT *" array from the database? Then, is there an opportunity to create a ListView with sorting based on calculated values?

Categories

Resources