課程
/移動開發
/Android
/Android攻城獅的第一門課(入門篇)
請問怎么在RadioButton弄一條函數式進去,當按下這個鍵時,得數是根據這條函數式得出來的
2017-10-20
源自:Android攻城獅的第一門課(入門篇) 21-6
正在回答
RadioButton是單選按鈕,多個RadioButton放在一個RadioGroup控件中,也就是說每次只能有1個RadioButton被選中。
? //設置who_group的監聽器,其實是一句代碼,其參數是一個帶有重構函數的對象? ? ? ?who_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { ? ? ? ? ? ?? ? ? ? ? ?public void onCheckedChanged(RadioGroup group, int checkedId) { ? ? ? ? ? ? ? ?// TODO Auto-generated method stub? ? ? ? ? ? ? ?if(checkedId == china.getId()){? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this,"中國", Toast.LENGTH_SHORT).show();? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?else if(checkedId == america.getId()){? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "美國", Toast.LENGTH_SHORT).show();? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?else if(checkedId == others.getId()){? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "其它國家", Toast.LENGTH_SHORT).show();? ? ? ? ? ? ? ?}? ? ? ? ? ?}? ? ? ?}); ? ? ?
qq_冰獨來獨往_0 提問者
舉報
想快速掌握Android應用開發基礎,選擇學習這門課程就對了。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-10-22
RadioButton是單選按鈕,多個RadioButton放在一個RadioGroup控件中,也就是說每次只能有1個RadioButton被選中。
? //設置who_group的監聽器,其實是一句代碼,其參數是一個帶有重構函數的對象
? ? ? ?who_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { ? ? ? ? ? ?
? ? ? ? ? ?public void onCheckedChanged(RadioGroup group, int checkedId) { ? ? ? ? ? ? ? ?// TODO Auto-generated method stub
? ? ? ? ? ? ? ?if(checkedId == china.getId()){
? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this,"中國", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?else if(checkedId == america.getId()){
? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "美國", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?else if(checkedId == others.getId()){
? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "其它國家", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ?}); ? ? ?