How many Activities do I need? - android

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!

Related

start listening #node but do not load data until data added

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 :)

how to use a list item to call and display a string in another fragment

i am a novice in android and i was trying to make an application that has two fragments, one with a listView with topics which when one is clicked it opens a topic description in the other fragment. i would like to know how to also store the large string for the description
If the data is dynamic you can store your topics and desciptions in a sqlite database. You have several possibilities:
You load the topic and description at the start and give over the description with a method or an interface to the second fragment.
You store the data in a database and give every entry a unique id and use a method or an interface to communicate with the second fragment and put the id to it. And then you use the id to get the description from database.
UPDATE #1
You can use arrays in your resource files. Create two arrays. One with your topics and the other with your descriptions. But the topics and descriptions have to be in the same order. For example the description of the second topic have to be on the second position in its array. Now you use the first array for your listview and the second(with the descriptions) in the description fragment. The "setOnItemClickListener" method of the listview have the position as a parameter. This is the same as the position of the topics and desciption in your arrays (when you dont resort anything).

How to save selected items from a listview to SQlite then view them on another page with titles?

I am building an android application (new to this)
There are several topics such as Cars, Phones, and laptops each having sublistings such as Mercedes, Chevrolet; Iphone,Samsung; Dell ,Toshiba. They are set in Listviews.
Now when the user clicks on Mercedes let's say I want this input to be saved in another activity in a list called Cars.Then he would select a phone and it would be saved permenatly in the latter activity in a list called Phones etc.
I have researched alot about SQLite databases but i still didnt hit any wins
Any quick help is appreciated.

Creating a scrollable list of items that can be ordered according to different criteria?

II would like to create a scrollable list of items that can be sorted according to different criteria that can be chosen by the user from the action bar; I was thinking of a button that says:"Sort by...". I am working on an Android app.
I am developing a tourist guide, or rather, making an app out of a paper tourist guide I have previously written, thus I have a list of monuments through which the user can browse.
It would be great if the user could sort the items of the list in alphabetical order, or according to the rating of the monuments or on the basis of a tag indicating their type (historical building, museum, etc.).
Would it be even possible to display under the name of each item, like a sort of subtitle, a series of dots or stars indicating the above-mentioned rating?
At last but not the least, would it be possible, only when the monuments are sorted by name or rating, to automatically group them by another tag?
Like in some song player apps, when you choose an artist, you get all of his/her songs displayed often grouped by album. In my case the grouping tag would represent the zone in the city of the monuments.
Despite my experience in publishing, I am a newbie in Android (followed just a few courses) and the API docs made me very agoraphobic about coding. I know I am asking much so I don't demand a detailed explanation but a few suggestions about what could be a solution, a bunch of helpful guidelines and some names of specific API docs about Array Lists and sorting methods I should look at.
Thanks already for your help.
Firstly, you need to have a custom Java Object for a particular item
for example:
public class CustomItem{
private String Name;
private int Rating;
private String Tag;
// getters and setters
}
Then you can create a Listview with Input consisting of a List of type CustomItem. Here is a good ListView tutorial: http://www.vogella.com/tutorials/AndroidListView/article.html
You can then have somethibng like a Spinner, in which you can add the sort criteria. When the user selects one sort criteria, you can sort the Input List for the ListView and refresh the listview by doing: listView.getAdapter().notifyDataSetChanged();
Hope this helps.

Android application structure issue

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.

Categories

Resources