Listview contents saving to Sqlite database-Android - android

I ve a ListView with two TextViews.This is my result page.So I need to store the results to sqlite database.I have a save Button.When user click on that save button there should be a popup appears that contains new-user and list of existing users.When I select new user the data will save to a new table with table name as new user name.When I click an existing user the data will add to the existing table.Ho can I achieve this.? How to create a table dynamically..??

As per your query -
When your pop-up appears:
On the click of new user button - Create a form for submitting new user details.
and
On the click of existing users button - use user contacts API to add users from the contacts.
I would suggest you to save the user entries to a single table.

Related

Android sqlite pagination in TextView

I am using Android studio with SQLite database is built-in, I am fetching some text from a table of 2 columns into TextView.
I want to use next and previous button
When the Activity starts, it loads the first record of a table in TextView but when I click on next button it should fetch next row of the table in TextView and when I click previous it should fetch the previous row of the table.
I am new to Android I searched about that but unfortunately found nothing.
try this. it could help you.
when a user enters in Activity fetch all data from Database and store that data in ArrayList at particular index . On click of Next Button get data from ArrayList according to it's index.

How to show only the items in specific country in listview?

I have a listView that show the user all item that saved in mySql database .. and for User table the user have his Country name .. my question is how I can show the user only item in his Country because I don't want to show him all the item in ListView when he open Main Activity.
Basically, you need to write your query with filter. You can use where clause to filter data and get only the data that belongs to the particular country. You can do something as mentioned below
SELECT * FROM Country WHERE CountryNama = 'yourCountry';
This will bring the record. And now you need to map the data in the model and add these in a list or array. And populate the date. Hope this will help you.

Saving Information Android

I am still fairly new to android and trying to learn day by day. I am trying to create a simple test application that you register for with an email/password to learn how to use save data from users.The app I am making is going to be simple, once they register and login, the user can search through a list of items I created on my MainActivity, and when they click on the listview item it will open a new activity. On the new activity, there will be a favorites button that I want to be able to click on and it will store that listview item information onto a favorites fragment I created and it will show the user a list of movies the user saved as favorites.
I am just trying to find out the best way I can do this. I have looked into SQLite and Firebase, hoping someone can explain to me which way would be the best way to approach this and maybe link me to a tutorial if possible.
Also the adding favorites to a listview item, if any one has a tutorial on that. I have already created my main listview and using Intents take the information and pass it to the new activity. It just clicking on the favorites button and saving the information into a new listview I do not know how to do, especially for when the users closes and re-opens the app the favorites will still be there.
Any help will be greatly appreciated.
To save favourite items in a new ListView you have to store the information somewhere. If you're using SQL, then store the Primary Key value in a favourites table that you can then use to find the corresponding information from the initial ListViews table.
If you are using firebase then each item in your list should have a unique key. Save that key and then when loading the favourites ListView, use the saved key to get the key's child data.
To summarise:
Store in a favourites table/branch the items the user selects as favourites and use that table/branch then to populate the favourites ListView.
I hope this helps
Another approach you could consider doing is storing your favorites using SharedPreference. The logic that would then follow is you have each row in your list view be an object that has an ID. Anytime a user favorites that object you save it into a set and store that set into SharedPreference that are corresponding to the current account username. You can then retrieve that set and show only the favorite objects for the user later on.
As for the SQLite vs Firebase question, I have not worked with Firebase yet, most of my interactions have been custom API calls. Having said that, I think SQLite would be a nice way to handle this as it would keep things easy and give you a good understanding of both sides of the equation.
Check out this tutorial. This very next one also covers SQLite:
https://www.youtube.com/watch?v=4SwAvFYMsXE

Firebase User Favourites List

Looking for a push in the right direction for creating a list of user favourites in Android. I have a list of items from a database which a user can scroll through and add to their favourites so when they log into their account they will be presented with a list of their favourite items. Is it possible to add an array or collection of some sort to the user so when they favourite an item then the primary id is added to some favourites parameter in their account which can be retrieved when they log in?
Sorry if this question is a bit basic, I am still new and am really only making this app to teach myself how to write android apps that use a database.
Thanks in advance!
Since you already have a database. I would add a new table or column to your existing table that would be set to 'true' or 'false' depending on whether or not the item is a user favorite.
This is better than a SharedPreferences because if you store row IDs you now have to manage that information in two places.
Additionally it's easy to get all items or just favorited items using an SQL query.
https://developer.android.com/training/data-storage/sqlite.html

how to fetch the value from sqlite database and display on new table layout in android

in my application,there are three screen..in first window(MainActivity) one button is here..when i click the button new window is open,there is edittext for user value..and also refresh button on second scrren ..
after entering value into edittext and refresh button the value are stored into database.my problem is that how to fetch them and display on new table layout in new window..
first screen
second screen
you may use button or any event to fetch the value from the database. you can run query on the database and store the value in the cursor. as far as code is concerned for fetching the value from the database you may http://www.vogella.com/tutorials/AndroidSQLite/article.html or http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html or http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Categories

Resources