Strip down the amount of layout xml required in an app - android

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/

Related

what is best for making dynamic screens?

I'm about to make an app that involves a lot of screens, its data structure is a tree with 4 levels and 84 final nodes that will contain check boxes at the end, I was thinking in using fragments but I dont want to make all that fragments, I am thinking there must be a more efficient way like to make a dynamic fragment that could load all the information (like text for the title or the check boxes) from a server or a data base, any ideas or suggestions for what could be easier and more efficient?

Android What's the best way to display several layers of varying types of nested data?

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.

Android Questonnaire layout approach

I want to create a questionnaire but I'm not sure what is the best way to approach this. I'm pretty new to Android but at the moment I have a working app which has a main activity screen which has various options. One of them is to launch the questionnaire. I have created a single database table which contains 4 columns Question Number, Question, Answer, Explanation. The explanation is displayed when the user selects the incorrect answer.
I am envisaging that the screen will be simple enough, just a textview containing the question and 3 buttons, 'YES' 'NO' 'BACK'. I plan to have 15 questions. What I'm wondering is do I have to create an activity for every question and every explanation even though the layout is going to be the same from one question to the next?
Definitely not!
Do this the way you would in any other application. Put your questions in some kind of list and iterate through them. Set the content "question" view, in your layout with the successive values.
... and remember to save the position in the list across Pause and Resume!
Ultimately to get this to work I had to use a counter which I incremented after each successive question. No list was required.

Android controls/layouts (How Instagram app does do that?)

I would want to know that how Instagram application listing/showing feed page?
Here is a screenshot: (I found it via Google and resized via tinypic.com. Here is the original file: http://www.digitaltrends.com/wp-content/uploads/2012/04/screenshotsjvc.jpg)
I am talking about 1st and 2nd screens.
As you know, when you go your feed (2nd screen) you can slide down and view other shares.
Every share has these:
Owner picture and username, shared time, a photo and a few things.
How to wrap all these datas in one control/layout in order to multiply?
Which control(s) (LinearLayout, Fragment, TableLayout and its TableRow(s)) are relevant for this kind of application?
I am not an expert Android application developer, that's why I want to know. I have confusion about that.
Thanks in advance.
As per my understanding screen 1 and screen 2 probably different fragments (take a look about fragments here). 1st fragment contains GridView (or some similar control) and 2nd one contains ListView.
I would suggest to begin with ListView. Basically, You will need to develop layout for single item (I think single RelativeLayout might be appropriate here) and then use it as item in the adapter.

Need To Create A Help component in Android

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.

Categories

Resources