I’ve released an app, and I recently found out that its not working 100% correctly in a foreign language (French to be exact).
It appears it works correctly until I create a cursor from a database and manipulate my returned data. I have text views that either gray out with default text, or it populates with what is returned from the cursor. What is happening is that it is doing neither of those things, and instead just uses the text that is in the layout I created.
Here is the code:
Cursor item = mDbHelper.fetchItem(mItemId);
String airline =item.getString(
item.getColumnIndexOrThrow(TripsDbAdapter.KEY_FIELD_FLIGHT_AIRLINE));
TextView itemAirline = (TextView)findViewById(R.id.flight_item_airline);
if(airline==null||airline.equalsIgnoreCase("null")){
itemAirline.setText(R.string.default_carrier);
itemAirline.setTextColor(getResources().getColor(R.color.light_orange));
}else{
itemAirline.setText(item.getString(
item.getColumnIndexOrThrow(TripsDbAdapter.KEY_FIELD_FLIGHT_AIRLINE)));
//itemAirline.setTextColor(getResources().getColor(R.color.white));
}
As you can see, I do a check to see if the database item called is null or “null” and change the text view accordingly. It doesn’t appear to be getting to that though since it doesn’t change at all. Keep in mind this has always worked perfectly when run on an English Language phone. The rest of my app seems to run fine in French as well except for this feature.
Here is my Database call too in case it is needed:
public Cursor fetchItem(long itemId) throws SQLException {
Cursor mCursor =
mDb.query(true, DATABASE_TABLE_ITEMS, COLUMNS, KEY_ITEMID + "=" + itemId, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
UPDATE
I am getting a LogCat message of an unparseable date when I switch my phone to the French Language. The code that parses the date is:
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
String itemDate = item.getString(
item.getColumnIndexOrThrow(TripsDbAdapter.KEY_DEP_DATE));
System.out.println("Before PArse Dates");
Date dateObj = df.parse(itemDate);
The date in question is of format Month, day, year. So I know where the problem is happening, but I still can’t figure out why. Any ideas?
I found that the unparseable date exception I was getting was just from incorrect formatting, and that my code was just stopping on the exception which is what caused my original problem.
For future reference, if you want to parse something like “2012-10-05”: