Wednesday, December 3, 2014

Hard coding text

  The advantage of taking some time off from coding is that when you come back to your project you are sort of looking at it with fresh eyes. I spotted something that should have been obvious before. I had hard coded text and that would be a problem when I added other languages to my app. 

Code before:

public void onItemSelected(AdapterView<?> parent, View view,

int position, long id) {
itemValue = (String) spinnerView.getItemAtPosition(position);
if (itemValue.equalsIgnoreCase("Add Vehicle")) {
// add has been selected so we change screens
addVehicleView();
} else if (!itemValue.equalsIgnoreCase("Add Vehicle"))
// vehicle selected so now we have to update previous fill
// up text
{
getLastSaved(itemValue);

}
                           }
Code after:
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
itemValue = (String) spinnerView.getItemAtPosition(position);
int count = spinnerView.getCount();
if (position == count - 1) {
                                // add has been selected so we change screens
addVehicleView();
} else {
// vehicle selected so now we have to update previous fill
// up text
getLastSaved(itemValue);

}




10,000 hour to Mastery.
10,000 - 619.25 = 9380.75 hours left