I created this little app where the city and area is asked to the user. Once the user enters the city, the area auto suggestions should get refined and suggest only the areas present in that particular city. I am using one city array by name "cities" and many other arrays which stores the areas in different cities for that corresponding city. EX: if the city selected is "abc" I have one another array with name "abc" containing the areas in the city abc.
How do I refine the search for area once the city has been entered, so that only area corresponding to the entered city is auto suggested? Do I need to use switch case?
The java file
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find);
this.text1 = (AutoCompleteTextView) findViewById(R.id.city);
String[] city = getResources().getStringArray(R.array.cities);
ArrayAdapter<String> adapterCity = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, city);
this.text1.setAdapter(adapterCity);
this.text1.setThreshold(1);
this.text2 = (AutoCompleteTextView) findViewById(R.id.area);
String[] area = getResources().getStringArray(R.array.Agra);
// In place of the array "Agra" the feed from text1 has to be used.
ArrayAdapter<String> adapterArea = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, area);
this.text2.setAdapter(adapterArea);
this.text2.setThreshold(1);
}
The string.xml
//array for the cities
<string-array name="cities">
<item>Agra</item>
<item>Aurangabad</item>
<item>Bilaspur</item>
<item>Vraranasi</item>
</string-array>
//area array for the city Agra
<string-array name="Agra">
<item>Agra-HO</item>
<item>Abc</item>
<item>Def</item>
<item>Ijk</item>
</string-array>
//area array for the city Aurangabad
<string-array name="Aurangabad">
<item>Abc</item>
<item>Def</item>
<item>Ijk</item>
</string-array>
Shall I use switch case(It would take a longer code involving cases for all the cities) or there's an inbuilt class, function for the same?