Hi to all the members of this great community!
This is my first question so forgive me for possible mistakes. I hope that from this day on i can be helpful for some of you as hopefully you will be for me.Getting to the question:
I am building an android app whose purpose is to search for nearest fuel-points and nearest care-repair-centers. I am very new to android and thx to the numerous posts about android in here I have managed to reach the point where i have build the map and animate it to my current location while updating my location.
Now i have to add the markers of the points of interest. Since they are at least 10 (I will add them only for demonstration purposes) i think it's not wise to add them through 10+ repetitive calls to itemizedOverlay.addOverlayItem(). My idea was to save them in a file in the format ( " latitude " , "longitude" , simple_description_title , other info ) and than in some way import the first 2 fields for the geopoint and the 3rd for the title.
I will use than the 4th later for some type of tooltip text (for example tel_number).
Do you think this is a good approach? And how can I implement the file reading(if) in the code that extends ItemizeOverlay().
I didn't post the code until this point since it's irrelevant.
Welcome to SO, let's jump right into your problem/question.
1.) Since you are only adding 10 points of interest it won't matter if you just call itemizedOverlay.addOverlayItem() for all 10 because the trick is to call itemizedOverlay.populate() only after you have added all the overlayItems using itemizedOverlay.addOverlayItem(), this way you don't compromise on performance.
2.) Now, once again, since you are only doing a demonstration I would advise you to simply hard-code all the 10 overlays with their respective geolocations into the Android code itself. This way you WON'T have to worry about reading data. Also, using a txt file to store data isn't the best option both performance and convenience wise. This is what databases exist for.
3.) If, and when you do this in the future, you do need to use some dynamic data to populate your markers with, then I'd STRONGLY advise you to use either
SQLite: The embedded database that Android offers, it's great for storing small bits of information that's required for your application such as description title, other info, the latitude, longitude, however, if you have some sort of a connection based application where you need to update globally accessible data every once in a while I'd advise you to use the next option,
MySQL: This is an online database that you have to interface with using a server and PHP. The advantage of using an online database is that you can now share information between different users (friends, contacts, followers etc.) by reading and writing to and from the database.
Related
I am building an app as part of a project and I am stuck at the moment.
Background: My team is making a "Time-Wasting" App, and the user can press buttons such as "study" to track their time spent on activities - so there will be lots of integers values in the growing ArrayList.
Task:
Store a growing Arraylist(integers) in the app store and retrieve the values for calculation and graph display purposes.
Problem:
I have looked so far how do to this, but I am a bit stuck. Do I use SharedPreferences, the internal app storage or something else. Also, I have a hard time finding code that I could look at and follow what it is doing.
I need:
An efficient way to store the ArrayList (integers) in a storage place and retrieve it for my app. Any suggestions what would be best and where would I find the code for that?
I looked for about 2 weeks through videos and a through stack overflow but I am still stuck and not closer to how I should store this data type in my app.
Thanks, any help much appreciated :)
My opinion avoid the array list and use a database.
It will allow your app to grow including storing extra information along with the time waster including when they chose to do it, how long , etc.
I recommend Room Database it is an ORM for Sqlite it is super easy to use and there is plenty of documentation on implementation as it's apart of the Android Jet Pack.
If you are really stuck on using a list you can use SharedPreferences it doesn't handle ordered lists but you can store your list as a json string.
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
What I want to do:
display a text box as an input field, which will accept a city name (any city throughout the world)
as the user starts typing, I'll auto-(complete/suggest) city names.
when the user selects a city name from the dropdown, the name appears in the text box as well, and the background gets highlighted to a very light blue.
Is there any existing widget that does this? If not, what would be a good way to auto-(complete/suggest) city names?
Edit: I know AutoCompleteTextView does autocompletes. The problem is more about dealing with an exhaustive datasource of cities (hopefully available as an API online somewhere), and connecting the widget with this list of datasource.
As you already pointed out yourself, a widget as described could be fairly easily built using standard components in the Android SDK, with the main one being an AutoCompleteTextView. In terms of "where to get the city data from", you basically have two options:
Bundle the data with the app.
Use a webservice.
Both obviously have their pros and cons. Bundling the data will blow up your APK size, a lot, whereas webservices are usually subject to a courtesy limit. Whichever option is the 'best', will depend on several factors, including the size of your app's userbase.
Some concrete resources for bundling the data:
MaxMind's Free World Cities Database (33MB)
GeoNames (233MB!)
And webservices:
GeoNames (cc-by licence, 30k requests/day, 2k requests/hr).
Google Places API - Autocomplete (1k requests/day, or 100k requests/day if you verify your identity with Google, or try your luck and request a higher courtesy quota)
Note that these lists are by no means exhaustive - I'm sure there are plenty of other options. They should offer you a decent starting point though.
You could try the AutoCompleteTextView class
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
I guess what you are looking for is something similar to Typeahead address picker.
https://github.com/sgruhier/typeahead-addresspicker
It can both recommend autocomplete while you type, and use a map to select/show the address. Looks good :)
Short version at the bottom
I'm working on an android app for a computer game, Heroes Of Newerth. A part of the apps functionality is to list all the heroes in the game. Each hero has:
a short description
a few stats(faction and primary attribute)
an icon
4 spells, which also has:
a short description
a few stats (mana cost, difference in ranks, etc.)
an icon.
There are approximately 110 heroes, which means I have about 500 sets of descriptions and stats.
I made a working version of the app. I downloaded all the images and put them in the drawable folder (note, this was 500 images), and created a Hero Enum which stored name, faction and primary attribute. Obviously, this was a bad idea, as it was horrible looking, and hard to extend to storing the rest of the data.
I have though about using a database, but as I don't have any experience with databases, I'm not really sure as how to do this, especially in Android. I looked it up, and it seems I need to initialize the database on the phone, which means I have to get that data from somewhere - which, again, means I'm back to square one.
I have never worked with this much data in a programming project, and have no idea for how to save it all. As if this is not enough, the game developer, S2 Games, releases new heroes with only weeks in between. As I wouldn't want to update one of my apps every other week, I want the app to be able to update itself with the new data. The best way I see this in my head is you download the app, either with a database of the current heroes, or without any, and the app checks each friday(patches are released on fridays) if the app is up to date. If not, update the database(with text and icons).
Short version
I want to save a few thousand strings, some formated in a special way(unless I can to this afterwards), and about 500 icons. How should I approach this?
Note: I know this was a really bad question, with a horrible structure, but I've been stuck here for weeks, and I couldn't get myself to ask someone, I really need help here!
well it's very recommended that you use sql and databases . you could go to w3schools for the basics .
if you don't want to use DB (or don't have time) , you can store all the data in xml files , and then parse them all . the images should never be part of the DB (or the xml files) , since they cause a bad performance while moving between items.put their names/paths instead .
if the images take a lot of space , consider using google expansion library .
I am working on a Text-Based RPG for Android (just built around the default views and buttons) to get a handle on some things before I launch into a more graphically intensive game. There is a Player who moves around Locations, and each Location has a set of possible Actions. The Locations and Actions have Strings for name and description, which are displayed by textViews.
My question is how to store the multiple Locations and Actions for the game? In its current state, I'm just calling new Location() multiple times in onCreate(), but with the 50 or so I'm planning on, the code would be massive, and I'm sure there's a better way to do it. I've thought about subclassing Location for each specific location, but that would be just as bad. I've also looked at JSON, and using an SQLite Database, and I'm sure there are other valid approaches as well.
Does anyone have any links, or suggesting for storing these "plot" related items?
If I understand correctly, at this time, you have the Location object initialization code - and the required data hard coded - in the onCreate method. This is a fairly good solution for a prototype, but if you want more, you have to outsource the data and lazy-initialize the Location objects when required.
If you are not planning on modifying the Locations, than I would suggest JSON, or even easier: an own text based protocol, that is easy to parse, and store it in files of the assets folder. For example like this:
LOCATION 14 Kitchen
LOACTION_DESCRIPTION Entering the kitchen you smell the freshly cut tomatos on the table...
ACCESSABLE_LOCATIONS 13 10 24 54
AVAILABLE_ITEMS 56 23 12 8
...
And you can parse the file line by line with a BufferedReader, building your object.
If locations contain information that may be modified and the modifications should be stored persistently, then you have to use a database. There are lot's of tutorials. This way you can save modifications.