課程
/移動開發
/Android
/Android攻城獅的第一門課(入門篇)
loginButton=(Button) findViewById(R.id.button_login);這里面的(Button)怎么理解?
2017-05-24
源自:Android攻城獅的第一門課(入門篇) 6-2
正在回答
findViewById找出來是View,你的loginButton是Button,不能直接賦View上去,所以前面加(Button)把View強轉為Button。
大概是Button loginButton = (Button) View
110177 提問者
強制轉換成Button類型,不然你在布局里的id是沒辦法使用的
將button_login轉化成一個Button類的對象(只有轉化成Button類的對象,才可以賦值給loginButton)
類似于(int)+一個浮點數,會將浮點數轉化為int型。
舉報
想快速掌握Android應用開發基礎,選擇學習這門課程就對了。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-05-24
findViewById找出來是View,你的loginButton是Button,不能直接賦View上去,所以前面加(Button)把View強轉為Button。
大概是Button loginButton = (Button) View
2017-05-24
強制轉換成Button類型,不然你在布局里的id是沒辦法使用的
2017-05-24
將button_login轉化成一個Button類的對象(只有轉化成Button類的對象,才可以賦值給loginButton)
類似于(int)+一個浮點數,會將浮點數轉化為int型。