这里主要是用户名与密码的判断:
先用sharedpreferences方式存储数据,包含用户名和密码:username,password
先看一下效果:
原理:把上一次选中的item对应的view缓存到oldDepartment中,当第二次点击时,如果点击的不是当前的item,那么去除oldDepartment的样式,给新选择的item添加样式。
android中的Selector主要是用来改变ListView和Button控件的默认背景。
属性介绍:
android:state_selected选中
android:state_focused获得焦点
android:state_pressed点击
android:state_enabled设置是否响应事件,指所有事件
1.Java代码实现
1 |
|
1.获取RadioGroup控件:RadioGroup radioGroup = (RadioGroup)findViewById(R.id.myRadioGroup);
2.获取RadioButton控件:RadioButton radioButton = (RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());
getCheckedRadioButtonId()必须在RadioButton选中之后调用,否则空指针异常。
3.获取选中的radio的值:String text = radioButton.getText().toString();