xml中使用自定义view

2bsimida 2014-06-09 03:12:45
在layout的xml文件中加入自定义view:
<com.ma.poker.GameView
android:id="@+id/gameview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
在该surfaceview加入构造函数:
public GameView(Context context,AttributeSet attrs) {
super(context,attrs);
this.activity = (myActivity) context;
由于view中需要使用Activity的handler,所以强转了context,但XML报错,所该处无法转换,怎么破?
好急好急,线等!!
...全文
92 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
2bsimida 2014-06-09
  • 打赏
  • 举报
回复
不能转的话 ,怎么调用activity中的handler?
何呵和喝 2014-06-09
  • 打赏
  • 举报
回复
context是不能随便强制转换的,所以楼上是正解。
triplesky001 2014-06-09
  • 打赏
  • 举报
回复
this.context=context;

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧