Android 控件(View)之 TextView Button ImageButton ImageView CheckBox
2010-02-27 23:48:00 来源:WEB开发网
_RadioButton.java
代码
package com.webabcd.view;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class _RadioButton extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.radiobutton);
setTitle("RadioButton");
RadioGroup group = (RadioGroup) this.findViewById(R.id.radioGroup);
// setOnCheckedChangeListener() - 响应单选框组内的选中项发生变化时的事件
group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
TextView txt = (TextView) _RadioButton.this.findViewById(R.id.textView);
txt.setText(((RadioButton)findViewById(checkedId)).getText() + " 被选中");
}
});
}
}
更多精彩
赞助商链接