Need an advice about one thing: I'm working on one application, which needs to display a lot of information about some items, which can be of different types with some similar attributes and some extra. Something like this:
Trade Mark
1. id : 211
2. name : Bla bla bla
3. Color : green
...
...
..
44. location
Invention
1. id : 211
2. name : Bla bla bla
3. Category : vehicle
...
...
..
44. location
So all these items are displayed in one List, but when you select one, it should show the more detailed information.
My question is: What is the best practice to display the data? should I create different activities for each category? Or should I create one activity and hide/show attributes related to the particular category? Or may be you can bring me to the light with showing something more effective. Gonna be very appreciated. Thanks! =)
What is the best practice to display the data?
Use a ListView/GridView with ViewHolder pattern.
should I create different activities for each category? Or should I
create one activity and hide/show attributes related to the particular
category?
Its really up to you, using a layout with show-hide method will decrease the number of classes in your project but make the code a little harder to read.
ExpandableListView is the way to go. No need for multiple activities or fragments. If you so wish you can make a fragment that contains the ExpandableListView but that's it - no need for multiple activities. If you are working with tablet's as well, then you might want to have a detailed fragment for the list item details when you click on a particular item. No more, no less, imho.
Related
I've read several SO posts and gone through some tutorials and now I'm trying to re-create this: http://i.imgur.com/on2xi72.png However, I'm not sure if what I propose to do is the best way to re-create this layout.
Here's what I'm proposing to do:
I'm working with this well nested JSONArray and JSONObject and vice versa API response (example data: https://jsonblob.com/5525b47ae4b0599c1fbd338b). I was thinking that I would create 3 different types of fragments to show the bullet point data. For example, one fragment would display "High Knees .. 25 yards" Another one could be a hyperlink type like in the case of "Shoulder Shrugs", and the final one would display the chart like the one at the bottom of the image. Since the API response separates data by a title like "Warmup" , "Upper Body Circuit", I was going to create a "block" activity that could contain the title and its related fragments/bullet point data. All of these "block" activities separated by the horizontal black lines would then be placed in another "full view" activity that would display stacked top to bottom. This "full view" activity would then be stored in another array because there are different dates to swipe through (if you notice at the top, it says Tuesday). Also, for each of these layers, there could be any type of variation and amount of data depending on the API call made. I hope this makes some sort of sense, haha.
Thank you for reading my post.
You can have only one activity per screen view in an android app, but can have several fragments per activity. Visual separation of your screen sections does not mean you need to have different fragments per sections in your activity. The reason you would want to use separate fragments is to be able to switch out the content of each fragment independently based on some application logic.
However, - if I understand it correctly - in your case, there is no reason why you would want to use multiple fragments per activity, as all your data is going to be changed as a whole based on the user/calendar day. Therefore, you can just use a single activity, or even better, use one fragment in your activity.
For your reference, this CodePath guide on Fragments may help you better understand fragments and how to use them. If you would like to read up on Activities more as well, you can do so on the android developer guides.
Lets say I want to create an Android app which shows a list consisting names of 200 people on the main activity. When users clicking on any name, they are taken to a screen showing the available info about that person. The details about each person may vary(some don't have an address, etc).
How will I tackle the issue of 201 different layout files(xml)?
I don't think it will be a good idea to make 201 activities.
If I use Fragments then I'll have to make 200 xml as well as 201 java files(for each different fragment).
If I use layout inflater or view switcher, even then I'll have to make 201 xmls.
So is there a way to strip down the number of layouts that will be required?
Are the layouts for each of the person different aside from the data e.g. address, name, etc. changing? Because if they aren't different you can use the same layout for each one of those people and just load the corresponding data of each person. If you can give me more information about how you store your data and how you display it I can give you a better answer.
No, you don't need that many files at all. In fact, all you need is your main screen containing the list of people, and then a screen containing the placeholder of the details.
When the user is clicked (presumably from some sort of listview) you can pass the details related to that user into the details activity where you can display it nicely, so reusing the same class/activity/layout.
This is a good tutorial showing you the basical mechanism of passing information between activities.
http://www.javabeat.net/how-to-transfer-data-between-activities-in-android/
I am new to Android programming, and I need some advice. I want to create an app that teaches children the alphabet and numbers. I want each letter to have their own screen which you can scroll to and from other letters, but each screen will be similar in that it will have the current letter, pictures of objects that start with that letter, and sounds corresponding with the letter and the objects in the background. Should I make one XML layout for these and somehow changed what letter and objects show up in on the layout using Java, make an XML layout per letter, or is there a way to create a base layout in Java and have all of the letters and numbers inherit these qualities and methods. If that is the case, would that require a Java class per letter as well? I am sorry if these seem like stupid questions, but most of my education in Android has come from internet video tutorials. I appreciate any and all help. Thank you for your help in advance!
v> I want each letter to have their own screen which you can scroll to and from other letters, but each screen will be similar
You probably want to check out ViewPager and Fragments for this.
This website usually seems to have pretty good tutorials. The docs and SO usually have good examples of getting started also.
Note These both require API >= 11 or using a compatibility package which you can find a tutorial Here. so that may be something to take into consideration. If that is an issue then you could simply have one layout with TextView, ImageView, etc... which retrieves its data from a DB and load them when a certain event happens such as a click.
Well, if you want a screen for each of the letters that you could swipe to, but each letter is going to have its own set of properties, I recommend you start looking for a ViewPager with custom Fragments. I think that is a good start. Then, you could focus on some other fancy features like sound.
I am building an Android application and would like to include a help component in it. The Help module would have a structure as shown below :
HELP
FAQs
Features
Placing Orders
Online Ordering
Mobile Application based Ordering
Phone Ordering
Managing my Loyalty Account
Signup
Points Catalog
Loyalty Status Tracking
Points Redemption
Accessing Order History
Purchase History
Insights
Reports
Setting Reminders
Helpline
As far as i could find, there are two ways of doing this kind of structure.
The first way would be to use a Multi-level ListView. The problem with this is that the code is quite complicated and that usually ListViews have equal number of child nodes. For example :- in the above mentioned layout "Features" has several children whereas "FAQs" has none. How would that work in a List View?
The Second Method is to use Buttons for all the first-level options and then create individual activity pages for each of the corresponding children. So the first page called "Help" would have 3 buttons as shown :-
HELP
FAQs
Features
Helpline
Upon clicking any one, a new page would open with either more buttons or some text; depending on what the user clicks.
My question is, which of the above two methods is better suited to my application? If there is another way to do this than the two i've mentioned I'd be happy to hear about that as well. I thank you for your time and patience in helping me.
Or you can use this open source project to create a TreeListView:
https://code.google.com/p/tree-view-list-android/
I can suggest the following structure:
The HELP Activity will contain 3 tabs
FAQ can contain the ListView of questions.
Features can contain the ListView with Section Deviders: Placing Orders, Managing my Loyalty Account etc.
Helpline can contain e.g. text and image.
This structure can be created using Eclipse Activities templates: Tabs or Tabs + Swipe or Swipe Views + Title Strip.
I'm trying to create and Android application which requires a number of search criteria which will eventually form an SQL query and run against a database.
The first set of criteria I'd like to present as a 3-tier list where the choices are dependent on the prior choice but there is only one final choice. So you could navigate to commadore via Car > Holden > Commadore. But you may only want to navigate to Car (and see a list of all cars) or Holden and see a list of all holdens.
Car
Holden
Commadore
Berina
Renault
Megan
van
van 1
Van 1 type 1
Van 1 type 2
etc
etc
There will also be other criteria such as colour, place and a free text search, I'd like to present these on a different tab or separate them somehow. I've looked at a tabbed layout but it appears that each tab uses a different activity and I believe that it is complicated for separate activities to talk to each other.
I'd appreciate any thoughts on this as I don't have time to discover all the shortfalls with this that others may have already experienced. Thanks for your help.
Much appreciated.
M
You can create Views instead of activities for the content of each Tab. The Activity which contains your TabHost will then be able to use the values selected from each of the views.
As for the lists, and sublists you can start to look in to the ExpandableListView, however that only provides a two level list, so you would need to look at extending it to allow n-levels I guess.
Alternatively you can have n-number of ListViews and transition between them IF the user makes a selection.