Android控件(View)之TextView, Button, ImageButton, ImageView, CheckBox
2010-09-27 02:07:00 来源:WEB开发网android:checkedButton="@+id/rad3" android:orientation="horizontal"
android:gravity="center_vertical|center_horizontal">
< RadioButton android:text="rad1" android:id="@+id/rad1"
android:layout_width="wrap_content" android:layout_height="wrap_content">< /RadioButton>
< RadioButton android:text="rad2" android:id="@+id/rad2"
android:layout_width="wrap_content" android:layout_height="wrap_content">< /RadioButton>
< RadioButton android:text="rad3" android:id="@+id/rad3"
android:layout_width="wrap_content" android:layout_height="wrap_content">< /RadioButton>
< /RadioGroup>
< /LinearLayout>
_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() + " 被选中");
}
});
}
}
7、AnalogClock 的 Demo
更多精彩
赞助商链接