android的常用控件总结
2014-06-05 17:23
363 查看
原文:原文地址
RadioButton单选按钮控件的使用方法
==================================================================================
1、RadioButton在main.xml中的布局
[html] view
plaincopyprint?
<RadioGroup
android:id="@+id/genderGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RaioButton
android:id="@+id/maleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
/>
<Button
android:id="@+id/famleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
/>
</RaioGroup>
2、//声明成员变量
[java] view
plaincopyprint?
private RadioGroup radioGroup = null;
private RadioButton maleRadioButton = null;
private RadioButton femaleRadioButton = null;
3、在onCreate(Bundle savedInstanceState){
[java] view
plaincopyprint?
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文件中布局
[html] view
plaincopyprint?
<CheckBox
android:id="@+id/swin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="游泳"
/>
2、//声明成员变量
[java] view
plaincopyprint?
private CheckBox swinBox = null;
swinBox = (CheckBox)findViewById(R.id.swin);
3、设置监听,用匿名内部类的方法
[java] view
plaincopyprint?
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中:
[html] view
plaincopyprint?
android:visibili="gone"表示进度条不可视
2、//android的ProgressBar的水平布局
style="?android:attr/progressBarStyleHorizontal"
==================================================================================
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Spinner下拉菜单控件的使用方法
===================================================================================
1、Spinner布局标签形式
[html] view
plaincopyprint?
<Spinner
android:id="@+id/spinnerld"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
2、在string.xml当中声明一个数组:
[html] view
plaincopyprint?
<string-arry name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Nepturn</item>
</string-arry>
3、创建一个ArrayAdapter:
//定义下拉菜单的样子
[java] view
plaincopyprint?
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(
this,
R.array.splanets_array,
android.R.layout.simple_spinner_item);
);
//设定Spinner的样式,引用android系统提供的布局文件
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
4、得到Spinner对象,并设置数据
[java] view
plaincopyprint?
spinner = (Spinner)findViewById(R.id.spinnerld);
spinner.setAdapter(adapter);
spinner.setPrompt("测试");
5、创建一个监听器,绑定在一起
[java] view
plaincopyprint?
spinner.setOnItemSelectedListener(new SpinnerOnSelectedListener());
6、监听器中的方法
[java] view
plaincopyprint?
SpinnerOnSelectedListener implements OnItemSelectedListener{
@override
onItemSelected(AdapterView<?> adapterView,View view,int position,long id){
String selected = adapterView.getItemAtPosition(position).toString();
System.out.println(selected);
}
@override
onNothingSelected(AdapterView<?> adapterView){
System.out.println("nothingSelected");
}
}
===================================================================================
ArrayAdapter的另一种用法:动态的创建ArrayAdapter
1、创建item.xml布局文件
2、
[java] view
plaincopyprint?
List<String> list = new ArrayList<String>();
list.add("test1");
list.add("test2");
ArrayAdapter adapter = new
ArrayAdapter(this,R.layout.item,R.id.textViewld,list);
RadioButton单选按钮控件的使用方法
==================================================================================
1、RadioButton在main.xml中的布局
[html] view
plaincopyprint?
<RadioGroup
android:id="@+id/genderGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RaioButton
android:id="@+id/maleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
/>
<Button
android:id="@+id/famleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
/>
</RaioGroup>
2、//声明成员变量
[java] view
plaincopyprint?
private RadioGroup radioGroup = null;
private RadioButton maleRadioButton = null;
private RadioButton femaleRadioButton = null;
3、在onCreate(Bundle savedInstanceState){
[java] view
plaincopyprint?
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文件中布局
[html] view
plaincopyprint?
<CheckBox
android:id="@+id/swin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="游泳"
/>
2、//声明成员变量
[java] view
plaincopyprint?
private CheckBox swinBox = null;
swinBox = (CheckBox)findViewById(R.id.swin);
3、设置监听,用匿名内部类的方法
[java] view
plaincopyprint?
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中:
[html] view
plaincopyprint?
android:visibili="gone"表示进度条不可视
2、//android的ProgressBar的水平布局
style="?android:attr/progressBarStyleHorizontal"
==================================================================================
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Spinner下拉菜单控件的使用方法
===================================================================================
1、Spinner布局标签形式
[html] view
plaincopyprint?
<Spinner
android:id="@+id/spinnerld"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
2、在string.xml当中声明一个数组:
[html] view
plaincopyprint?
<string-arry name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Nepturn</item>
</string-arry>
3、创建一个ArrayAdapter:
//定义下拉菜单的样子
[java] view
plaincopyprint?
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(
this,
R.array.splanets_array,
android.R.layout.simple_spinner_item);
);
//设定Spinner的样式,引用android系统提供的布局文件
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
4、得到Spinner对象,并设置数据
[java] view
plaincopyprint?
spinner = (Spinner)findViewById(R.id.spinnerld);
spinner.setAdapter(adapter);
spinner.setPrompt("测试");
5、创建一个监听器,绑定在一起
[java] view
plaincopyprint?
spinner.setOnItemSelectedListener(new SpinnerOnSelectedListener());
6、监听器中的方法
[java] view
plaincopyprint?
SpinnerOnSelectedListener implements OnItemSelectedListener{
@override
onItemSelected(AdapterView<?> adapterView,View view,int position,long id){
String selected = adapterView.getItemAtPosition(position).toString();
System.out.println(selected);
}
@override
onNothingSelected(AdapterView<?> adapterView){
System.out.println("nothingSelected");
}
}
===================================================================================
ArrayAdapter的另一种用法:动态的创建ArrayAdapter
1、创建item.xml布局文件
2、
[java] view
plaincopyprint?
List<String> list = new ArrayList<String>();
list.add("test1");
list.add("test2");
ArrayAdapter adapter = new
ArrayAdapter(this,R.layout.item,R.id.textViewld,list);
相关文章推荐
- Android常用控件总结
- android常用控件总结
- Android常用控件总结
- Android常用控件总结
- Android常用控件总结
- Android控件WebView的属性设置和相关常用方法总结
- Android中常用控件分类总结
- Android之进度条控件和常用资源分类总结
- Android常用控件总结
- android 自定义控件学习之三 控件布局常用知识总结
- Android常用控件总结
- android常用UI控件总结
- Android常用控件总结
- Android常用控件总结
- Android常用控件总结
- android的常用控件总结【安卓入门五】
- android常用控件总结(一)
- Android基础(四) 常用控件 - ProgressBar
- Android常用控件的基本使用说明
- Android学习笔记--Android开发时常用控件(三)