开发者

How to get instance of custom view instantiated in xml?

开发者 https://www.devze.com 2023-03-04 15:17 出处:网络
when i declare a view like this in a layout: <com.test.www.BrushPreview android:i开发者_如何学God=\"@+id/brushview\"

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

精彩评论

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