close

xml:

<RadioGroup
        android:id = "@+id/RadioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <RadioButton
        android:id = "@+id/music"
        android:text="Music"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <RadioButton
        android:id = "@+id/sport"
        android:text="Sport"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />
    <RadioButton
        android:text="computer"
        android:id = "@+id/computer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RadioGroup>

 

java:

//RadioGroup
RadioGroup radiogroup = (RadioGroup)findViewById(R.id.RadioGroup);
radiogroup.setOnCheckedChangeListener(rtn);

......

//RadioGroup
    private RadioGroup.OnCheckedChangeListener rtn = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            RadioButton rtn_music = (RadioButton)findViewById(R.id.music);
            RadioButton rtn_sport = (RadioButton)findViewById(R.id.sport);
            RadioButton rtn_compnter = (RadioButton)findViewById(R.id.computer);
            if(checkedId == rtn_music.getId()){
                setTitle("我的興趣是:" + rtn_music.getText());
            }
            else if(checkedId == rtn_sport.getId())
            {
                setTitle("我的興趣是:" + rtn_sport.getText());
            }
            else if(checkedId == rtn_compnter.getId())
            {
                setTitle("我的興趣是:" + rtn_compnter.getText());
            }
        }
    };

arrow
arrow
    全站熱搜

    淺翔 發表在 痞客邦 留言(0) 人氣()