This question is slightly different from others of the same name. I am not trying to update the data in the list, I am trying to update the look of the list.
My application is fragment based using the support library. I have a PreferenceActivity where I allow the user to set the colors that they would like to use for the text in the list (the adapter reads the preference and sets the colors). This works for the most part.
The problem I have is as follows. When I have a list on the screen (this is a ListFragment) and pull out the menu, select "Preferences" and make changes to the color preference. Upon returning to the list from PreferenceActivity, I cannot get the list to redraw itself with the specified new color.
If I go from the list and return to it, it will be updated with a new color.
I am trying to use onResume
to make changes. The code I have (which does not seem to do anything for the list, but changes the color of the title as it should):
@Override public void onResume() { super.onResume(); header.setTextColor(MyApplication.header); line.setBackgroundColor(MyApplication.header_line); subheader.setTextColor(MyApplication.header); getListView().invalidateViews(); }
I tried invalidateViews
and invalidate
. In desperation, I tried calling notifyDataSetChanged
on the adapter, even if there were no changes in the data itself. Nothing seems to work.
Am I missing something obvious or is there no way to do this?
EDIT
The getView method from my adapter:
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = View.inflate(context, layout, null); View row = convertView; c.moveToPosition(position); TextView first = (TextView) convertView.findViewById(R.id.ListItem1); TextView second = (TextView) convertView.findViewById(R.id.ListItem2); TextView third = (TextView) convertView.findViewById(R.id.ListItem3); TextView fourth = (TextView) convertView.findViewById(R.id.ListItem4); DecimalFormat df = new DecimalFormat("0.00"); Double hold = Double.valueOf(c.getString(3)); Double qty = Double.valueOf(c.getString(1)); Double total = hold * qty; String color = "#FF00FF"; first.setText(c.getString(2)); first.setTextColor(MyApplication.shoplistitem_name); second.setText(c.getString(4)); second.setTextColor(MyApplication.shoplistitem_desc); third.setText(c.getString(1)); third.setTextColor(MyApplication.shoplistitem_qty); fourth.setText("$" + df.format(total)); fourth.setTextColor(MyApplication.shoplistitem_desc); if (strikethroughState[position] == 1) { first.setPaintFlags(first.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); second.setPaintFlags(second.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); third.setPaintFlags(third.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); fourth.setPaintFlags(third.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); row.setBackgroundColor(MyApplication.shoplistitem_checked); } else { first.setPaintFlags(first.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); second.setPaintFlags(second.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); third.setPaintFlags(third.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); fourth.setPaintFlags(third.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); row.setBackgroundResource(R.color.black); } return (row); }