I have 10 TextViews, their text and visibility is stored in an SQLite db. When an activity loads, I need to grab these values and apply them to the TextViews.
My db is currently structured as: _id, textviewID, text, visibility. What would be the best way to access these values and apply them to the correct TextView?
Take a look at this article, this post, and of course the Android Developer's topic on how to retirieve values from an sqlite db.
For these kind of configurations SharedPreferences are way more handy solution. If your design is not strict to use the local database for storing application preferences, you should consider it as an option.
Related
So I am wondering about how necessary it is to store variables in the realtime firebase database if I want all Users at access the same dynamic variable.
So for instance, I have a arraylist that stores the list of open games, and if I want this list to update in realtime for every user should this List in firebase realtime database?
Sorry for the simplicity of the question
Yes, it may be a simple question, but it surely pops in head of everyone, once.
I think for updating any list dynamically in real time, would require you to access any kind of database.
It is not necessary to have it on Firebase database, but any database online, that can tell every open instance of your app that the list has to be updated at a particular instant.
The main reason of why you need it to be on database is updating it in real time and that too dynamically.
If it's not dynamic, meaning the content that you need, can be hardcoded then one way would be placing everything you need in your code and using timer or something like that to fire at particular moments to update things in your app.
Also that aside, sorting, storing and changing data is much simpler using a database, which also becomes one more reason for you to use a database like Firebase to keep content of your app that has to be updated frequently in real time.
You can know more about database in this Google link, I found.
I have an android app with user login i need to store the login details in my app.
My app also has some user history of certain request made by him/her.
My app is a software service app so user details must be stored in app which is fetched from the database
Is Sqlite or sharedpreference suitable for my application?
Depends, If you only want to save sessions of user use SharedPrefrence or else if the data is more you can use sqlite
/**
* method to set the login status for the application
*
* #param context
* #param status
*/
public static void setLoginStatus(Context context, int status) {
sharedPreferences = context.getSharedPreferences(PREFERENCE_NAME, Activity.MODE_PRIVATE);
Editor editor = sharedPreferences.edit();
editor.putInt(KEY_LOGIN_STATUS, status);
editor.apply();
}
NOTE :
About that its totally on your choice what you use to save the current
state of user , i will prefer using shared preferences. And for signup
and sign in use SQLite database. Shared preferences are commonly used
to perform light operations. You can search through data in SQLite as
you may have many users.
So use SQLite to register and login and then use shared preferences to
save tha current state of user.
Sqlite is always a better option to store the data there you can manage in proper format and you can encrypt as well.
I would suggest, you should use sharedPreferences for saving the login details and i suppose whatever request you are storing, contains more data, so save your requests in SQLite.
Here is some good details about theme :
Pros and Cons of SQLite and Shared Preferences
SQLite
Large amounts of same structured data should be stored in a SQLite
database as databases are designed for this kind of data. As the data
is structured and managed by the database, it can be queried to get a
sub set of the data which matches certain criteria using a query
language like SQL. This makes it possible to search in the data. Of
course managing and searching large sets of data influences the
performance so reading data from a database can be slower than reading
data from SharedPreferences.
SharedPreferences
SharedPreferences is a key/value store where you can save a data under
certain key. To read the data from the store you have to know the key
of the data. This makes reading the data very easy. But as easy as it
is to store a small amount of data as difficult it is to store and
read large structured data as you need to define key for every single
data, furthermore you cannot really search within the data except you
have a certain concept for naming the keys.
According to the Size or Format of your data you can choose one, for login information I suggest using SharedPreferences
I'm looking for the simplest way to bind a value in a SQLite column to a textview. I have about a hundred textviews across a number of activities.
I have a DBHelper class to define the table and columns and a SQLController class to define my methods to insert, get and update data. All of this is pretty much boilerplate code.
For each activity I open the database, set my cursor and get the data, then update it back to the database when the activity closes.
Is there a library I can use to bind the fields in my db to the textview directly? I currently use butterknife to bind the data objects to the views and am considering implementing android data binding, but I was wondering if there's a way to go directly from the database to the view without having to write all this boilerplate code?
I need help with adding a database in my app for android. What I want to do is save name, address, if certain checkboxes are checked and textbox data. so far this is what I have in my main activity xml and java (download links):
https://www.dropbox.com/s/vp4fg0f5kx0p5it/activity_main.xml?dl=1
https://www.dropbox.com/s/p2dkqtoe8h1dl85/MainActivity.java?dl=1
All the other questions and tutorials just don't seem able to be grasped by my mind. I want to save the "name", "address", "AirSealing", "airsealnotes", "DuctSealing", "BlowerDoor", "ductsealnotes", "blowdoornotes", "Light", "lightnotes", "othernotes", "HPD", "HPGJGNY", "Placeholder", and the save button to save data.
There's a lot of boilerplate code associated with creating and handling an SQLite database (even just one with a single table), so don't feel bad about not getting it right away.
Here's the tutorial I personally used to grasp SQLite databases in Android:
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Essentially, you'll want to follow the tutorial, only replacing their columns (a name and phone number) with the data you want to store. The custom helper class isn't mandatory - you can simply take the code they put in the DB handler class and write it in your main activity class instead - but it makes writing and retrieving data a lot easier.
Also, a word of warning: you won't be able to store every type of data in a database out of the box. For instance, if you want to store a boolean (which would be your checkboxes), you'll have to do it by storing, say, an integer or a string, instead of an actual boolean.
I currently have a UI for users to select reminders on Activity A. These reminder attributes are saved in a database, and the reminder is populated into a listview on Activity B. How would I go about selecting a reminder item on the listview on Activity B, grabbing this data from the database, and populating the UI of Activity A with the data that was previously selected.
Is there a standard to do something like this? Should I create the selections as a serialized object to be saved in the database and then use this data? Or should I just save each attribute as a field in the database and have each saved item as a field?
I am pretty new to this stuff, so I am not sure if I should go with a database, shared preference or content provider.
One approach is to use a Content Provider, which provides a consistent point of access to your database. With a ContentProvider, you can take advantage of the Loader framework (also available via the Support Library), CursorLoader, and CursorAdapter to keep your ListView in sync with your database.