I have Spinner or ListView with flag icon and currency name (I save their R ids in sqlite, for example R.drawable.aed and R.string.aed from drawable folder and string.xml)
Then I insert new drawable, for example cxx.png
My flag icons shifts, some of them changes with other images, not flags icons. This happen if I update app on my phone. If I install it, or delete and then install all work fine.
I understood, that sqlite in my program save R Ids of drawables only once on install. When I add or delete drawables or strings, R changes ids numbers, but in my sqlite table saved old R ids.
I can try to write method, that will update all R ids in sqlite everytime when I will add or delete new strings and drawables, by increasing DB_VERSION each time. Is there simpler solution?
This is one of my Adapters:
public class SpinnerCursorAdapter extends CursorAdapter {
public SpinnerCursorAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.spinner_item, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
view.setTag(viewHolder);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder viewHolder = (ViewHolder) view.getTag();
int flagIconId = Integer.valueOf(cursor.getString(5));
viewHolder.flagIcon.setImageResource(flagIconId);
String currencyName = cursor.getString(4);
viewHolder.currencyName.setText(currencyName);
viewHolder.currencyCharCode.setText(cursor.getString(1));
}
private static class ViewHolder {
final ImageView flagIcon;
final TextView currencyName;
final TextView currencyCharCode;
private ViewHolder(View view) {
flagIcon = (ImageView) view.findViewById(R.id.spinner_flag_icon);
currencyName = (TextView) view.findViewById(R.id.spinner_currency_name);
currencyCharCode = (TextView) view.findViewById(R.id.spinner_currency_char_code);
}
}
}