Android学习笔记-常用控件
2016-02-04 11:05
543 查看
单选按钮 Radio
runBox = (CheckBox) findViewById(R.id.run);
readBox = (CheckBox) findViewById(R.id.read);
//...
swimBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
System.out.println("Swim is checked");
} else {
System.out.println("Swim is unchecked");
}
}
});
readBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
System.out.println("Read is checked");
} else {
System.out.println("Read is unchecked");
}
}
});
runBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
System.out.println("Run is checked");
} else {
System.out.println("Run is unchecked");
}
}
});
}public class MainActivity extends ActionBarActivity {
private ProgressBar firstBar = null;
private ProgressBar secondBar = null;
private Button myButon = null;
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstBar = (ProgressBar) findViewById(R.id.firstBar);
secondBar = (ProgressBar) findViewById(R.id.secondBar);
myButon = (Button) findViewById(R.id.myButton);
myButon.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
if (i == 0) {
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
}else if (i < firstBar.getMax()) {
//设置朱进度条的值
firstBar.setProgress(i);
//设置第二进度条的值
secondBar.setSecondaryProgress(i + 10);
//默认的进度条无法显示进行的状态
//secondBar.setProgress(i);
}else {
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i = i + 10;
}
}
}<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/user_name"
android:layout_width="180dip"
android:layout_height="30dip"
android:textSize="10pt"
android:singleLine="true"/>
<TextView
android:id="@+id/user_ip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="10pt"
android:gravity="right"/>
</LinearLayout>
genderGroup = (RadioGroup) findViewById(R.id.genderGroup);swimBox = (CheckBox) findViewById(R.id.swim);
maleButton = (RadioButton) findViewById(R.id.maleButton);
femaleButton = (RadioButton) findViewById(R.id.femaleButton);
//...
genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (femaleButton.getId() == checkedId) {
System.out.println("female");
Toast.makeText(MainActivity.this, "female",
Toast.LENGTH_SHORT).show();
} else if (maleButton.getId() == checkedId) {
System.out.println("female");
Toast.makeText(MainActivity.this, "male",
Toast.LENGTH_SHORT).show();
}
}
});
runBox = (CheckBox) findViewById(R.id.run);
readBox = (CheckBox) findViewById(R.id.read);
//...
swimBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
System.out.println("Swim is checked");
} else {
System.out.println("Swim is unchecked");
}
}
});
readBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
System.out.println("Read is checked");
} else {
System.out.println("Read is unchecked");
}
}
});
runBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
System.out.println("Run is checked");
} else {
System.out.println("Run is unchecked");
}
}
});
}public class MainActivity extends ActionBarActivity {
private ProgressBar firstBar = null;
private ProgressBar secondBar = null;
private Button myButon = null;
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstBar = (ProgressBar) findViewById(R.id.firstBar);
secondBar = (ProgressBar) findViewById(R.id.secondBar);
myButon = (Button) findViewById(R.id.myButton);
myButon.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
if (i == 0) {
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
}else if (i < firstBar.getMax()) {
//设置朱进度条的值
firstBar.setProgress(i);
//设置第二进度条的值
secondBar.setSecondaryProgress(i + 10);
//默认的进度条无法显示进行的状态
//secondBar.setProgress(i);
}else {
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i = i + 10;
}
}
}<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/user_name"
android:layout_width="180dip"
android:layout_height="30dip"
android:textSize="10pt"
android:singleLine="true"/>
<TextView
android:id="@+id/user_ip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="10pt"
android:gravity="right"/>
</LinearLayout>
相关文章推荐
- Android学习笔记-Activity的布局
- Android学习笔记-Activity的生命周期
- Android学习笔记-EditText&TextView&Button&菜单栏
- Android学习笔记-Activity&Intent
- Android学习笔记
- android selector用法
- ANDROID 返回,菜单和HOME键的监听
- Android 之LocalBroadcastManager
- Android NestedScrolling 实战
- Android样式的开发:selector篇
- Android 自定义命名空间
- 编译Android4.3内核源代码
- Android开发的那些坑和小技巧
- Android布局之相对布局——RelativeLayout
- 关于MpAndroidChart的折线图问题
- Android 第八天 (上午)
- Android子线程向主线程发送消息实现
- Android 编译使用高版本的Java
- Android WebView 因重定向无法正常goBack()解决方案
- Android垃圾回收机制解决内存泄露问题