Android的常用控件总结(一)

2014-11-24 09:54:01 · 作者: · 浏览: 5

2、//声明成员变量
private RadioGroup radioGroup = null;
private RadioButton maleRadioButton = null;
private RadioButton femaleRadioButton = null;


3、在onCreate(Bundle savedInstanceState){
radioGroup = (RadioGroup)findViewById(R.id.genderGroup);
maleRadioButton = (RadioButton)findViewById(R.id.maleButton);
famaleRadioButton = (RadioButton)findViewById(R.id.famaleButton);
//监听处理,内部类去实现
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener (){
public void onCheckedChanged(RadioGroup group,int checkedId){
if(famaleRadioButton.getId()==checkedId){
System.out.println("famaleButton is checked!");
//toast弹出消息框
Toast.makeText(当前类.this,"famale",Toast.LENGTH_SHORT).show();
}
else if(maleRadioButton.getId()==checkedId){
System.out.println("male is checked!");
Toast.makeText(当前类.this,"male",Toast.LENGTH_SHORT).show();
}
}
}
);
}
==================================================================================、。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
CheckBox多选框的使用方法
==================================================================================


//CheckBox的使用方法,不存在组的概念


1、在main.xml文件中布局
android:id="@+id/swin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="游泳"
/>


2、//声明成员变量
private CheckBox swinBox = null;
swinBox = (CheckBox)findViewById(R.id.swin);


3、设置监听,用匿名内部类的方法
swinBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChange(CompoundButton buttonView,boolean isChecked){
if(isChecked){
System.out.println("swin is checked");
Toast.makeText(当前类.this,"swin",Toast.LENGTH_SHORT).show();
}
}
}
);
==================================================================================
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
ProgressBar进度条控件
==================================================================================
1、android中的控件ProgressBar中:

android:visibili="gone"表示进度条不可视


2、//android的ProgressBar的水平布局
style=" android:attr/progressBarStyleHorizontal"
==================================================================================
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Spinner下拉菜单控件的使用方法
===================================================================================
1、Spinner布局标签形式
android:id="@+id/spinnerld"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>


2、在string.xml当中声明一个数组:

Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Nepturn


3、创建一个ArrayAdapter:
//定义下拉菜单的样子
ArrayAdapter adapter =
ArrayAdapter.createFromResource(
this,
R.array.splanets_array,