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.
Related
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
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.
I have been storing option lists for my Android app in a cloud table. For example, categories like "historical fiction","biography","science fiction", etc. I see the following pros and cons:
Pro:
I can make changes to the list without sending an app update to Google Play
Not normalized - I can use the text in my other data tables instead of a reference ID
Con:
App needs to take time to download from the web each time (or at least check for changes)
English only
I believe the "proper" way to do this is the use the XML resource files. But I need to make sure the selection references correctly with my data. That is, my app needs to understand that "Poetry" and "PoesÃa" are the same thing.
Is the correct thing to do:
Forget about it since I'll never get to the point where I'm translating my app anyway
Use a string-array and use the index (0...x) to know what the selection is
Use a 2-dimensional string-array with a reference ID in the first column and the text in the second?
If you are handling the category list online, then why not handle the translations online as well. Here is what I would suggest:
In your application options, have a list of supported languages (each in their native translation). These language options should be stored on whatever server application is handling your web requests. Each language is associated with an integer ID that the user does not see, but is stored in the app.
Whenever you issue a web request to get a list of options, include the language id in the message. This will allow you to know what language the user has picked and can use a 2D array or some other structure to handle the conversion to and from the chosen language.
I'm not sure if this helps at all, since I don't know exactly what you are making or how you are designing it, but from the given description, this is an easy and effective course of action.
I am looking to create an app that has about 50 pages of static content. I can give an example of what it would look like, so that it will be easy to understand the questions.
Imagine a Jokes app, with tens or hundreds of pages
The user can see a full list of jokes, which shows the headings in a list view
Selecting a joke subject will take them to the joke page
From there they can go 'Next' or 'Previous'
They should also be able to favorite a joke
Going to the Favorites pages, will list the favorites for them
The joke pages are static. I could add more jokes with an app update but there is no dynamic content. So I am planning to have any server side code that the app can call.
Now the questions:
In Android, can I achieve this with a single activity (for the joke display) and switch the content based on selection?
There are several to store the jokes - sqlite, separate html pages or just strings.xml. Which is better for these use cases?
If there are multiple headings within a single joke (i.e. formatting as bold for them to stand out), I need to store the formatting along with the content. So HTML looks like the option?
This may be out of scope, but I want to capture the content in a standard way so that if I build an iOS app for this, I can just worry about the UI part and use the same content. Again HTML is the option?
Thanks for looking.
Yes you can achieve this with a single activity.
This is really up to you but Android provides support for SQL Databases. You may also consider looking into content providers.
Note: I would not use strings.xml because you can't load new jokes into strings.xml. If you are getting your jokes dynamically from a website, then you really should either load your content into a database and have the app display from the database, or else just load each html page individually. The html page will be easier as you will basically just be making a browser app, but the database will certainly be faster and cleaner.
HTML is certainly an option, though this question seems a little bit vague. It really depends on how you want to get your jokes. If you want to grab them as HTML pages and just display them, then the work is done for you. If you want to parse through them and display them as an android specific app, then it will be more work but you have more control on the app side.
Yes if you want your app to work cross platform you can use HTML to standardize your view across multiple devices.
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);