How can I get a firebase query result into a spinner adapter in android. The image above is a sample structure of my database. I want only those that available to be shown in the spinner, and only the the number is to be shown, so in this example 0954555 will be shown, but in the query i have to get only those whose available is yes. Thank you :)
Related
I am fetching a list of dogs from an endpoint. Some of the attributes of the dog, color for example, are identified by id. The id's and colors corresponding to the id were all saved in a database when the app is opened. I am using MVVM architecture and assume that the model is consuming the response data correctly.
In the main screen of the app, I have a recyclerView that will populate with a list of dogs. when I fetch the list of dogs, I am returned the id of the dog's color as part of the dog object. The user isn't going want to see the id of the color, but the actual string value of the color corresponding to that id. I need to query the database with that id to get back the string value of the color to display to the UI.
My question is how would I go about doing this? The recyclerView adapter would be where the UI is updated, and I would need the position of the dog to know what color Id I am fetching, but I can't run that query from the adapter as it would lock up the main thread. I thought to create a function in the view model that would update that particular list item, but I think I would still need the position from the adapter. I'm not really sure how to proceed...
I hope my question isn't too confusing, I had a hard time figuring out how to ask! Thanks for your time!
You want to build proper query in your DAO and "join" values from another table, depending on color_id.
You are not allowed to do any queries at adapter level. Data passed to adapter must contain everything you need.
Joins and mappings are described here: https://developer.android.com/training/data-storage/room/accessing-data
I'm developing android app and want to fetch some result from sqlite db inside the app and display it in "ExpandableListView". here is what i want. The app will provide some list of disease(problem) for the user to select and when a specific disease is selected, a query will get executed based on the selected disease and fetch 'TradeName' from db that have the same 'ActiveIngredients'
The ActiveIngredient will be the PARENT list and all tradeNames that contain the active ingredient will be the CHILD list.
Previously i have used to normal ListView to populate the results but when the data is populated redundant ActiveIngredients will be listed.
The expected output should look like this.
In my Android app I have an activity with a listview that displays about 4000 items that are stored
locally in a SQLite Database. If I make an edit to an item, how can I get only this change in the listview,
without having to refresh all the item list (which means a new query for 4000 results)? This query slows down the performance.
I would like something like NSFetchedResultsController of ios.
Strategy should be -
As you are editing the contact, if the update is successful you just fetch the latest info from db for this specific contact only.
Update the edited contact object in your adapter's source List/Array's specific position.
Invoke your adapter.notifyDataSetChanged().
you must have an id for each contact in your SQL lite database.
when you edit a contact update that specific record in your database on basis of the id.
if update is successfull means the information you sent to database is stored successfully .
now you can use the same informtion to update your ArrayList/HashMap whatever you are using to populate your listview.
Ex:- suppose you edited 3rd index contact in your listview on successfull update you add like yourarraylist.add(3,contact);
and the fire notifydatasetChanged.
Try these steps if possible:
Try to fetch the data from db, but do it in different thread which won't effect the main UIThread.
Then you can call the adapter.notifyDataSetChanged() on adapter object. It will do the job i hope :).
In my android app I have a search screen.
The content is stored in a database, and a listview is populated via a ListAdapter.
This all works correct.
But I want the following functionality.
When a user searches, but gets no result, I would like to give him/her the option to add the search item.
for example:
list in listadapater is: [monkey, donkey, mouse]
when the user searches for: lion, he will see no results.
But I want the option to add lion to the database list.
Hopefully someone can get me in the right direction.
Thanks in advance,
Goldhorn
You simply add the new item into the database. Then you requery the database for a new cursor which you then pass to the adapter.
Can someone point me to right direction, how to create an adapter for AutoCompleteTextView, which would be getting data from SQLite DB, using data, which user entered into the text field? I want to use the user-entered data to filter suggestions for autocompletion. I imagine that adapter should always take user-entered data as soon as changes appears and use it for fetching suggestions on-the-fly. Is that possible? So far I've seen many tutorials for autocompletion where static String arrays were used, but never seen them build dynamically. Is it possible to do it automatically or I need always fetch String array myself and pass as ArrayList to adapter on every AutoCompleteTextView change?
You might be looking for CursorAdapter. Use it just like an ArrayAdapter, but instead of feeding it with an ArrayList, provide a database Cursor. Google for CursorAdapter and you should get a lot more example codes.