为了账号安全,请及时绑定邮箱和手机立即绑定

自定义控件实现button功能,重写点击方法后安卓崩溃

自定义控件实现button功能,重写点击方法后安卓崩溃

慕仰2209588 2016-03-13 15:56:41
public TitleLayout(Context context, AttributeSet attrs) { super(context, attrs); // 利用layouInflate.from(context).inflate(传入layout,父活动) LayoutInflater.from(context).inflate(R.layout.title, this); Button titleBack = (Button) findViewById(R.id.title_text); Button titleEdit = (Button) findViewById(R.id.title_edit); titleBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ( (Activity) getContext() ).finish(); } }); titleEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), "You clicked Edit button", Toast.LENGTH_SHORT).show(); } }); }上面是自定义的Title,有一个title。xml在Layout中,然后在activ_main.xml中用    <com.example.helloworld.TitleLayout         android:layout_width="match_parent"        android:layout_height="wrap_content"        ></com.example.helloworld.TitleLayout>安卓一打开就关闭,求救
查看完整描述

1 回答

?
慕雪1579370

TA贡献1条经验 获得超0个赞

你把TitleLayout 的其他构造函数添加上去试试。

查看完整回答
反对 回复 2018-02-05
  • 1 回答
  • 0 关注
  • 2326 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号