課程
/移動開發(fā)
/Android
/Android攻城獅的第一門課(入門篇)
請問怎么在RadioButton弄一條函數(shù)式進(jìn)去,當(dāng)按下這個鍵時,得數(shù)是根據(jù)這條函數(shù)式得出來的
2017-10-20
源自:Android攻城獅的第一門課(入門篇) 21-6
正在回答
RadioButton是單選按鈕,多個RadioButton放在一個RadioGroup控件中,也就是說每次只能有1個RadioButton被選中。
? //設(shè)置who_group的監(jiān)聽器,其實是一句代碼,其參數(shù)是一個帶有重構(gòu)函數(shù)的對象? ? ? ?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_冰獨(dú)來獨(dú)往_0 提問者
舉報
想快速掌握Android應(yīng)用開發(fā)基礎(chǔ),選擇學(xué)習(xí)這門課程就對了。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-10-22
RadioButton是單選按鈕,多個RadioButton放在一個RadioGroup控件中,也就是說每次只能有1個RadioButton被選中。
? //設(shè)置who_group的監(jiān)聽器,其實是一句代碼,其參數(shù)是一個帶有重構(gòu)函數(shù)的對象
? ? ? ?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();
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ?}); ? ? ?