开发者

How to get instance of custom view instantiated in xml?

when i declare a view like this in a layout:

<com.test.www.BrushPreview android:i开发者_如何学God="@+id/brushview" 
    android:layout_width="100dip" android:layout_height="100dip"  
    android:layout_gravity="center"/>

how do it get the instance of my BrushPreview? I need to invalidate it...

Cheers


Inside your activity you can get the view instance of @id/brushview of the underlying layout by

final BrushPreview brushview = (BrushPreview) findViewById(R.id.brushview);

If it's inside an other, repeatedly used view, like an item renderer of a list view, then you must first select the appropriate item, and call findViewById on it:

final BrushPreview brushview = 
    (BrushPreview) itemRenderer.findViewById(R.id.brushview);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜