I'm trying to show a list of songs on a recyclerview in android, nothing too fancy. something like this:
Song1
in Album a
-Song2
in Album a
-Song3
in Album b
So far so good; also, my firebase db looks something like this (in my app, a song cannot be on two albums, so bear with me)
songs:
-idSong1:
description:"Song1"
album: idAlbumA
-idSong2:
description:"Song2"
album: idAlbumA
-idSong3:
description:"Song3"
album: idAlbumB
albums:
-idAlbumA:
description:"Album a"
-idAlbumB:
description:"Album b"
Okay, enter Android adapters. I set a firebase valueListener to songs, retrieve all of them and pass them on to the adapter. The problem is, I still don't have the description of their albums.
Let me clarify, I do have the id's of the albums, but I'm forced to set a value listener of every item to find out the album description. I'm not familiar with firebase but it doesn't take much to know that that can't be right. I would be setting and removing listener a lot when the user scrolls through the song list.
There is a high chance I might be approaching this whole thing the wrong way. So any kind of advice is welcome.
Lastly, I want to congratulate the guys at firebase for such an amazing product!
Well, it turns out what I was trying to do was to simply do a JOIN between two nodes. and here's how it's done: https://www.firebase.com/blog/2013-10-01-queries-part-one.html
Related
I try to make an app on Android for services reviews, every review is save like an element in the document "user" like this-
Everytime the user save a report I have see if inside the reports the field "plate" is existing comparing with the new one, I try query using the examples in the page arrays in Firebase
In the code i tried get with "whereEqualTo" method search by "reports.plate" or with the method "whereArrayContains" with the same field (the filter uid exits but in the first image doesn't show) any idea how i can search the document when some of the custom elements fields is equal
maybe sorry in advance for the english i'm practicing
Thanks in advance
I'm using firebase database to store data. I know how to use firebase database.
In my project I've an activity which displays a list of notices from faculties to students and by clicking on list item it will open another activity which is a chat room. In this activity student can ask question related to given notice.
Now, In first list activity I've also added on text view which displays the total number of chat messages for that particular Notice. It works well when i load data from database initially. But i want to change number of chat messages dynamically.
So, i need to listnen at chat_cnt node to update value of message_cnt text view
and problem is it is a big list so i can not use child_added for each and every notice item and if i use value_event listener than it will load all data unnecessarily at start.
The code is a little bit big so i cannot post it here. But I've described the problem.
Any answer would be appreciated, thanks. Sorry for my english :)
I'm in the middle of making my first Android app and have been asked to make an app that displays information on books. I currently have a login screen which brings me to a new page of buttons with different genres. When you click on a genre it brings you to a listview of books in that genre, you then click on a book and it should display information on that book.
My main issue is, I have made a lot a activities already and I'm wondering if I'm going about this the wrong way? When I get to displaying information on each of the books that will be clicked inside of my listview, do I then have to make a new activity for each or is there a better way to do this that I seem to be missing?
Try the following pattern:
Create your first activity for Login (i.e LoginActivity.class)
Create your second activity that contains your genres (i.e GenresActivity.class)
Create your third activity that contains a list of books in that particular genre - remember this will be reused for all genres because it is simply a list of items. (Have you heard of RecyclerView instead of a ListView?)
Create your 4th activity for details of a book (i.e BookDetails.class) - this will also be reused each time to display a book's information. The caveat would be to have the same structure/layout used because a book object has the same information like title, author, year and perhaps cost. So, when a user clicks a book from a list, you want to direct them to a details view where they can view more information on that particular book!
That brings you to 4 activities - not too many if you think about it.
I hope this helps! Good luck!
I have a listview in which a user adds his comments on a particular topic, these are then stored on server,
as multiple users may add comment i wish the listview to update periodically (say 10sec),
and add only the latest data and not the complete data as it will slow down the application.
How do i do this.?
Fix some Buffer Comments something like 50. If the number of comments is more than 50 then display the last 50 comments only. Implement pagination concept from the server. Keep some 'Load More' button or Auto Load functionality(just like in twitter or facebook) for viewing more rows in the List.
I'm working on application and I need some suggestions which is the best way to code it for Android. Basically it's something like event guide for a few cities. Imagine this :
I have an activity with 7 different buttons (7 different cities) and clicking on one of these buttons I'm opening a new activity where I have all months (January-December) as buttons again. If there is some event in February for example in the chosen city the button will be active and I will go to another activity where I have a list with the events. So my idea is to do it in this way :
Create one Activity with all Cities
Create one Calendar activity with all months.
When user select for example Paris, I'll send an extra via intent with an ID of the chosen city :
intent.putExtra("chosenCity", 2); //something like this
In the Calendar activity I will make active/inactive months buttons depending on that extra sent from Cities activity.
And when user chose a month I will send that chosenCity extra again to the ListViewEvents activity and populate the list view from Database (for example) depending on that extra.
So my question is : is it a good way to build an application like that? Or if it's not, which is the best way to achieve this?
Thanks in advance!
Sounds like you already know pretty much what you need to do. The only thing left is to implement it. The only thing I'll add is that your should probably store all your database and use a CursorAdapter to display them in the ListView. You can store all the events in the database and just create your select statement in such a way that it only selects the events you want to display at any given time. When using this CursorAdapter, I highly recommend you use the CursorLoader.