Split up forms for user input in Android - android

This is an easy question, but I don't know how to word it to get a result from Google.
I am currently building an app in Android. One of the features of the app includes inputting a large amount of personal data (i.e. emergency contact information, social security number, and others). The file will include around 40 fields, but I don't want the user to have to scroll through one layout to fill all this information out. Thus, how do I create new "forms" to populate without having to create a new activity and xml layout for each set of data?
Any help is appreciated. Thank you for your help.

Thus, how do I create new "forms" to populate without having to create a new activity and xml layout for each set of data?
You are welcome to create a new fragment and XML layout for each set of data, if you prefer.
At the end of the day, your code is largely the same in all cases:
You need all 40 fields in an XML layout file somewhere. Whether this is one file, two files, or ten files, is up to you.
You need to your controller logic for handling that input from those 40 fields somewhere. Whether that is in one activity, N activities, or N fragments, is up to you.
If you are expecting Android tools to be able to magically generate all this for you, just by you thinking really hard and staring at your monitor, Google's Project Synapse has not yet been released yet. :-)

Related

Asking for advice of how to appraoch an application

as part of a university project, i have to build an android app that will contain informations about diseases, the diseases will be listed in a list (alphabetic order), when clicked on a disease you'll be directed to another layout that contains informations about the disease chosen (including text and images).
i'm new to this and i don't know how to approach this app..and for the text should i build a database or directly input the text inside the app or something like that .if you know a tutorial or something that would help please share
Ps: there is almost 60 Diseases and each disease will have a subitems (causes, treatment, clinical signs .)
thanks
First of all, the comments are right. Please be more precise in your question. Ask what specific problem occured, if possible provide code samples, errors and research state. https://stackoverflow.com/questions/how-to-ask
UI Design (List)
there is almost 60 Diseases and each disease will have a subitems
Therefore I would suggest an ExpandableListView.
Check out this code sample: https://www.journaldev.com/9942/android-expandablelistview-example-tutorial
Afterwards if the user clicks on an item, you open another Activity with details
Data Storage
should i build a database or directly input the text inside the app or
something like that
Static approach
As you can think of, putting data directly into views makes it difficult to maintain, but is faster implemented and less difficult.
Implemenation: I would suggest putting the data into res/raw as a .json file. In your code, build a JSONObject out of it and pass it to the ListViewAdapter.
Dynamic approach
You need Internet permission, a webserver and a remote database from where you can query the data.
Implementation: If you have a hosted webserver you probably have PHP and MySQL databases. Create a table, fill it with data and build an API in PHP where you provide the data from the database. If you have a VPS or dedicated server you can use MongoDB which works with JSON out of the box.
My guess
For an university project, use static. Otherwise dynamic of course.
Hope this helps

Design choice for Android app

I am new to Android (but proficient in programming) and I have been reading the Google documentation.
I am trying to build a small app, just to get familiar with Android (not a very fancy app, just for learning app dev).
The app would have an initial activity containing a list of items, and the user can view them (through another activity), edit them (again another activity) or create new ones (again another activity). My concern is how to store this list of items in the phone.
I do not intend (at the moment) for the app to be synced with any external service, so I am happy to store all the data in a file. Typically I would be looking at 200 items of small size, so a text file (maybe XML or JSON) would be enough I think (SQL would probably be overkill here).
My question is: if I have an XML file with all the items, do I need to parse it and load it in memory for every activity?
For example:
the user enters the app to see the list of items -> must load the XML
the user wants to add a new item-> I need to load the XML again to be able to add an XML child
Is this the most natural way of doing this in Android? having to load the same resource over and over in each activity?
Thanks
If you want to reuse files you may use adapter. You can either create custom adapter or use default one. Besides that you may know programming concepts such as Design Patterns. My point is to reuse in android can be done programmatically.
In your for storing data would be better to use SharedPreferences here tutorial to understand idea about it
If you don't want to use SQL to store your data, you can try SharedPreference.
And yes, you have to load all values in everytime you read or write. But don't worry, it won't be hard for mobile phone hardware.

Creating an android app with static content

this is a bit of a non-specific question where i need some guidance.
As part of a project we did, i need to create an app that has information about a town - the best places to visit and their history etc. the content is all static with images. The 'interactive' functions users have is to filter sites of interest based on Historic, cultural etc. There will be about 50 such sites. An idea was to use the Master Page - such as we use in ASP.NET. But as a newcomer to android i do not know if there is such a thing as the master page in android. I read an article where they derive for each activity from a base activity, but in my case having 50 activities just sounds stupid.
Can anyone suggest an approach? Store the text in strings? use separate text files?
I will try to give you an overview of the app you are trying to create.
First, you would have an activity, say CategoryListActivity, which list out all categories (i.e. Historical sites, Cultural sites, for example) using ListView.
When the user clicks on Historical sites, it launches another activity called PlaceListActivity. You pass an additional param to this activity using Intent, telling it that you want to show places in historical sites only. It will show all available places that fits your criteria, using ListView again.
Now when the user clicks on one of the places, it launches third activity called PlaceDetailsActivity, which shows all information related to this place. It is up to you to determine how to show these information.
So you just need min. 3 activities in total (of course you will need a bit more). Regarding your data, storing all text inside SQLite database would be a great choice. You can assign each place and category with an id, so you can tell CategoryListActivity and PlaceListActivity to load data dynamically. The only hard-coded data, is when you trying to populate the database on first launch. However, you can always prepare the database first, pack it with your app, and ask your app to load and use it immediately.
I would store all the text in an embedded SQLite database, and all the media in the assets folder.

Can I display multiple screens content using single activity

Iam developing an android application wherein i need to manage good amount of data. I have 2 doubts.
I planned about 25 screens(pages) in this application. To display each and every screen do I need to create a seperate Activity or can i manage it with single activity. Which option will increase the performance of the application and which one is better.
I have very good amount of data. Do I need to store in SqlLite database or can I store it in string.xml resources file.
While designing the screens are there any constraints that are to be followed. Please suggest me.
1) IT is always better to have a separate activity for different tasks as it increase the readability and maintainability of your application code.
2) I would not recommend using one single activity because it will make your class very cluttered and at some point of time it will become very difficult to make further amendments in your code.
3) You can use strings.xml as a replacement of database as it is not meant database purposes. If you have a large amount of data than you have 2 options:
i) If this data is static and not going to change in near future than use sqlite database.
ii) if this data is dynamic in nature and requires frequent update and sync than you must choose a web based service for handling this data.
i want to add that you can do this but it's not a good idea as mudit said ,
you can do something like this :
this.setContentView(R.layout.home);
//do some work here ,Click on a button for example
this.setContentView(R.layout.detail);

Android card based game, need help to start

I'm just setting out in android development. I want to make a kind of card based game. I'm just looking for suggestions really on how I might start it.
I know I have to make the menu layout and view, then use an Intent from that to get to the main game view. My sticking points are:
There's going to be a deck of cards. It's going to be a set number so I was thinking I could just have each card defined as a button in the layout. I don't know if that is the right way to do it though.
Storage of card details. I'm thinking of using an xml file to store these.
You could try to check out this project:
http://code.google.com/p/bestcardgameever-android/
And a post of the author about this (there is a second post in the same blog):
http://developreality.blogspot.com/2009/05/overcoming-absolutelayout-deprecation.html

Categories

Resources