My scenario:
I am populating a ListView in an activity that is displaying a list of city names. When I select a city name, I am launching a new activity that will display the name of the city in a TextView header. This is working perfectly, using a “getIntent” call in my new activity.
I then want to populate another ListView in my new activity listing all the streets in the city.
Here is my problem. In my database, I have a table of city names that I am calling in my first activity. The fields within this table representing the city names contain spaces (example, San Francisco).
My though was to pass this data to the new activity, and then package the results in a new rawQuery command to query the street names that exist within another database table that would contain all the streets for a specific city. The issue is that table names cannot contain spaces (so my table is named SanFrancisco). That’s fine, except I don’t want to display “SanFrancisco” in my first activity, I want to display “San Francisco”.
Would the solution to create another field within my List of Cities table that would contain the non-space version of the city word, and pass that to the new activity as well? If so, how would I do that considering I don’t display that in my initial ListView?
ADK,
You don’t want to create separate tables for each of your cities. All you need are 2 tables and you can add as many cities and streets as you want and you can even still use spaces if you want to keep passing the full city name.
You just need 2 tables: “City” and “Street”.
Here’s the query to run:
If you want to switch from passing the full city name to the city’s unique id when someone clicks the row, you just need to change the last line in the SQL statement to “where c._id=1”.
There are easy ways to do the queries with Android content providers so you should look that up too.