android - LayoutInflater sometimes (randomly) inflates with wrong background color -
i inflate view layoutinflater. background color of inflated relativelayout set in xml file. have experienced strange issue on 1 of devices: (randomly) background color other (wrong) color colors.xml. have met problem before?
details:
i have listview cursoradapter. inflate list items one, static item (so think it's not recycling issue), using code:
@override public view newview(context context, cursor cursor, viewgroup parent) { layoutinflater vi = (layoutinflater) context.getsystemservice(context.layout_inflater_service) ; view v = vi.inflate(r.layout.bookmark_item, null) ; //bindview(v, context, cursor) ; log.wtf("newview", "view color: " + integer.tostring(((colordrawable) (((relativelayout)v.findviewbyid(r.id.bookmark_row)).getbackground())).getcolor())) ; return v; } my layout/bookmark_item.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="wrap_content" > <relativelayout android:id="@+id/bookmark_row" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/app_menu_item_background" tools:ignore="uselessparent" > <textview android:id="@+id/bookmark_item_title" android:layout_width="match_parent" android:layout_height="wrap_content" /> </relativelayout> </relativelayout> the inner relativelayout's background color set @color/app_menu_item_background. color in r.java:
public static final int app_menu_item_background=0x7f0a0036; i have color named @color/app_menu_item_colored_background, use elsewhere in code, has nothing common bookmark list , adapter. has different resource id in r.java:
public static final int app_menu_item_colored_background=0x7f0a0038; and both of them different colors:
<color name="app_menu_item_background">#517409</color> <color name="app_menu_item_colored_background">#f6efde</color> then, when running app, (not always), view using wrong app_menu_item_colored_background background color. logged inflated view colors (see code above), , differs sometimes:
"newview" - "view color: -11439095" "newview" - "view color: -593954" note, first color #517409, second #f6efde.
strangely, reproduce error on 1 device, samsung galaxy s3 mini, 2-3 times every 10 tries.
try manually
v.setbackgroundcolor(getresources().getcolor(r.color.app_menu_item_colored_background));
Comments
Post a Comment