
我的应用程序基于片段使用支持库.我有一个PreferenceActivity,我允许用户为列表中的文本设置他们想要的颜色(适配器读取首选项并设置颜色).这在大多数情况下都按预期工作.
我遇到的问题如下.当我在屏幕上显示列表(它是一个ListFragment)并拉出菜单时,选择“首选项”并更改颜色首选项.从PreferenceActivity返回列表后,我似乎无法使用指定的新颜色重新绘制列表.
如果我离开列表并返回它,它将使用新颜色重新生成.
我正在尝试使用onResume进行更改.我目前拥有的代码(似乎没有对列表执行任何 *** 作,但会更改标题颜色):
@OverrIDepublic voID onResume() { super.onResume(); header.setTextcolor(MyApplication.header); line.setBackgroundcolor(MyApplication.header_line); subheader.setTextcolor(MyApplication.header); getListVIEw().invalIDateVIEws();} 我尝试过invalIDateVIEws并使其无效.无奈之下,我尝试在适配器上调用notifyDataSetChanged,即使数据本身没有变化.似乎没什么用.
我错过了一些明显的东西,还是没有办法做到这一点?
编辑
我的适配器的’getVIEw`方法:
@OverrIDepublic 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);}解决方法 notifyDataSetChanged()当然应该为你工作.你是如何处理偏好变化的?如果您只是将首选项提交给SharedPreferences,那么它永远不会更新静态MyApplication变量.你可以发布你用来设置偏好的代码吗?如果您没有使用它,请为颜色首选项设置onPreferenceChangedListener()以在更改时设置该静态变量. 总结 以上是内存溢出为你收集整理的android – 如何强制重绘listview?全部内容,希望文章能够帮你解决android – 如何强制重绘listview?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)