亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自定義控件實現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 關注
  • 2350 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號