textview常用属性
EditText : 文本输入框
ImageView : 图片视图
CheckBox : 多选框
setOnCheckedChangeListener:校验开关
RadioGroup/RadioButton : 单选框
代码
public class Simplecomponent extends Activity {
TextView tv_simple_msg;
EditText tv_tishi;
Button tv_safasdfa1;
Button id11;
ImageView img;
CheckBox CheckBox1;
CheckBox CheckBox2;
CheckBox CheckBox3;
CheckBox CheckBox4;
RadioGroup mandan;
boolean ife=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//初始化布局
setContentView(R.layout.activity_simplecomponent);
// ---------------------(设置TextView提示框)---------------------------------
// 获取对tv_simple_msg的操作
tv_simple_msg=(TextView) findViewById(R.id.tv_simple_msg);
// 设置tv_simple_msg显示的内容
tv_simple_msg.setText("今天天气不错,pm2.5才800-_-!");
// ---------------------(设置EditText输入框)-----------------------------------
// 获取对tv_tishi的操作
tv_tishi=(EditText) findViewById(R.id.tv_tishi);
// 设置默认数
tv_tishi.setText("128138733");
// -------------------(设置ImageView图片)-------------------------------------
// 获取img的操作
img=(ImageView) findViewById(R.id.tupian_sim);
// 设置点击事件(new了一个OnClickListener点击接口重写方法)
img.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 点击内容
if(ife){
// 设置背景(用android.R是系统自带)
img.setBackgroundResource(android.R.drawable.alert_light_frame);
// 设置前景(单R是自己的,/R.drawable.ic_btn_up_pressed指向图片)
img.setImageResource(R.drawable.ic_btn_up_pressed);
ife=false;
}else{
img.setBackgroundResource(android.R.drawable.alert_dark_frame);
img.setImageResource(R.drawable.ic_btn_up);
ife=true;
}
}
});
// -----------------(设置CheckBox多选框)---------------------------------
// 获取操作
CheckBox1=(CheckBox) findViewById(R.id.CheckBox1);
// setOnCheckedChangeListener校验开关点击事件
CheckBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
new MyToast(Simplecomponent.this,"全中了足球");
}else{
new MyToast(Simplecomponent.this,"取消了足球");
}
}
});
CheckBox2=(CheckBox) findViewById(R.id.CheckBox2);
CheckBox3=(CheckBox) findViewById(R.id.CheckBox3);
CheckBox4=(CheckBox) findViewById(R.id.CheckBox4);
id11=(Button) findViewById(R.id.id_mys);
id11.setOnClickListener(new OnClickListener() {//确认yes点击
public void onClick(View v) {
StringBuffer buffer = new StringBuffer();//用append追加数据
if(CheckBox1.isChecked()){
buffer.append(CheckBox1.getText().toString()).append(",");
}
if(CheckBox2.isChecked()){
buffer.append(CheckBox2.getText().toString()).append(",");
}
if(CheckBox3.isChecked()){
buffer.append(CheckBox3.getText().toString()).append(",");
}
if(CheckBox4.isChecked()){
buffer.append(CheckBox4.getText().toString()).append(",");
}
new MyToast(Simplecomponent.this,buffer.toString());
}
});
mandan=(RadioGroup) findViewById(R.id.mandan);//主要把组获取到了
//给组创了一个点击事件setOnCheckedChangeListener校验开关.new了一个接口
mandan.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
public void onCheckedChanged(RadioGroup group, int checkedId) {
//checkedId的id就是选RadioButton的id
//找到选中的RadioButton
RadioButton e=(RadioButton) findViewById(checkedId);
//的到文本
String string = e.getText().toString();
//提示
new MyToast(Simplecomponent.this, string);
}
});
}
// --------------------------------------------------
public void tv_safasdfa1(View v){//测试常用的component
String trim = tv_tishi.getText().toString().trim();
new MyToast(this, trim);
}}