Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
So I have a custom list of restaurants. When the restaurant is clicked I want a set of data coming up (Name, phone number, rating, category) and I want the user to be able to modify that data and for that data to remain the same when left from that screen. Is there any way to store the data for each restaurant? Thanks
If you want user changes to only be preserved in his device only then using a database is the best option. I highly recommend going with Room Library
First of all, you should define your restaurant model as an entity for room;
define a Dao object to create, list and edit your entities;
define an abstract class as the database. Room will provide the implementation at compile time itself;
access and manipulate database items using dao object in database implementation.
For details on the steps mentioned this guide is the best place to start.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I'm new to Java.
Say I want to make a simple game with Swing or whatever. How and where do I store variables like the player's score or progress, for example, so that I can access it from different classes (during the game and before persistence in the database). I like how we use useContext in React. I also used global variables in PHP's sessions.
I highly advice to not use a "global state". I would rather recommend to implement a domain object or service that fetches high scores. This service can then be injected and called where needed.
Using a domain object or a service to access and modify domain data has the benefit that ownership is clearly defined: the business object/service owns the data, and the data is only accessed and modified through the business object/service.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm new to using a database, specifically MySQL. I'm creating a web application for class in which you can look up the name of a book and it'll display the summary of the book. My question is should I send a query to the database that collects all of the books' data on initialization and put them into a HashMap inside a manager class for lookup or should I use a query each time to lookup a specific book information?
It depends on the data transport time I would say. If your average query time times the number of request goes faster than a script to put everything into a HashMap, use queries. Otherwise, use a script that collects everything and puts it into a HashMap.
But if you have thousands of rows, you should use queries, because otherwise you will use too much RAM.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I would like to create a table which is filled by data from DB. I know that it is possible to create a dynamic table using TableLayout but I'm not sure that it's the best solution im my case.
Here is an example of what I want to create(the first table on the page).
I'll give you my inputs on this.
If your data is limited and you are sure to display all of it in a single screen in a presentable manner, then yes, a TableLayout will suffice.
However, in a real world, flexibility counts so you should always consider the possibility that your data may expand in the future. Keeping that in mind, you should use a ListView or a RecyclerView in this case. Define a base layout for each row of your list or recycler view and then connect the data from your database to this view using a suitable adapter.
For starters:
https://developer.android.com/training/material/lists-cards.html
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there any way to edit a string which is already on a text file using vectors in Java? For example, the user inputs the employee number asked by the program and then the user will input the name and age. The modified info will be updated to the text file which serves as employee records.
Vector is just a data structure. It cannot be used to read/write employee records from/into files. It can, however, be used to keep employee records in memory.
To implement the functionality that you need, you need to:
Think on how the employee records are represented in file. Is it in CSV? XML? JSON?
Once you decide the representation, you need to write two methods. One that reads the file, and returns employee records in a Vector. Two that accepts employee records, and write them into file.
Write the main program that operates on this Vector.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a dilemma on how to implement this requierement:
Let's say I have the following Contact classes
Student,
Tutor,
AdminStaff.
I am not sure what is the best way to structure it in DataStore:
shall I have one Contact entity which will contain shared fields and also corresponding extra fields for given type
or shall I have three separate entities
first approach allows me to search through all my contacts, and the second is to avoid extra filtering when I just need contacts of certain kind.
However I have one more requirement which I am not sure how to accommodate with any of these approaches. What if I have contact with multiple personalities e.g. Tutor and AdminStaff. This suggests I have a separate Contact entity and link to its various personalities. So for the above example I would have data about that person kept in three entities Contact,Tutor,AdminStaff.
I would appreciate for any suggestions
Regarding your concern about searching over all your contacts - even if you have 3 different entity types, I think you could still create an index that would allow you to search over all contacts.
I don't know how many attributes there are that are unique to the different contact roles, but I'd be worried about creating a single mega-class/entity that encompassed them all - it could be a very big and messy class.
And, as you have indicated, your final requirement does make things more complicated. It suggests that perhaps you should have a single contact class/entity for all roles, and then create class(es) for the 3 roles that can be #embed'ed into to the contact entity.