ArrayList with Multiple data - android

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.

Related

Make Score History in Array Field Firestore

How to make history score in Array
I try u make score in array like this
this my firestore
And this is my code
String uid = auth.getCurrentUser().getUid();
muridref.document(uid).update("nilai", FieldValue.arrayUnion(skortampil));
When I get the same score the array field doesn't make new Array data,
without see data there or not in array
As mentioned in the documentation Update elements in an array about this behavior:
If your document contains an array field, you can use arrayUnion() and arrayRemove() to add and remove elements. arrayUnion() adds elements to an array but only elements not already present.
Considering that, it's working as expected, since it's not adding values that are equal. So, this means that you won't be able to add values that are equal using the method arrayUnion() directly.
This other question from the Community - accessible here - indicates that for you to achieve this goal, you will need to read all the values from the array in your client side, update your values in the array outside the database and then, writing/updating it back in the database.
Let me know if the information helped you!

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

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

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).

Android: different objects in one list

I am a new to android developing. I am developing an android app for a shopping mall...
i want to have a screen where a list is displayed. Name of the mall and its photo should be displayed in the first section with its short one line address...
In the next sections the products should be displayed in the same way....
Product photo, Product Name and its price...
Please suggest me what topics should i read to create such a screen....
could fragments be used to create this screen???
Thanks in advance...
There are many ways. Like you can create a Customized List view for each screen. You can first create an Array List of objects of MallClassPojo. Like:
ArrayList<MallClassPojo> mallList.
Where your MallClassPojo contains the getter setter methods for Mall name,Mall image url or resourceID and short description of mall. Pass this mallList to your adapter class. Retrieve the details and show them in your customised List View. The next screen can be prepared in the same way also.
Well then you can create an Array List of JSON objects. In a JSON Object you can add different data like in one object you can add the company data and in another you can add product data. Isn't it?

android listview issue with more than 3 dynamic data

I have a doubt. I have 3 array list dynamic values. I need to display these dynamic values in a listview. can someone please tell me how can i achieve this.
I have name[] array, status[] array and image[] array. I need to dynamically display the values in listview in a android sample
This is what i have:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,NameList);
In this i am able to display i am able to display all the names in NameList[].
An array list only accepts an array of values, so as you see, you can only pass in the names. You have two options,
The simple option is to create a compound object, say Person, that has a name, status, and image. Then you create a Person[], and create the array list on that, and pass it into the array adapter. You must implement Person.toString() to print out the Person object as you'd like.
If you need to be able to lay out the Person fields in a more flexible way then you could simply by implementing toString() on Person, you need to create a custom list adapter. You can take a look at this post to get you started,
Categorise the listview

Categories

Resources