我正在研究一些现有的Windows窗体的数据绑定,并且我遇到了一个问题,想出了在一个组框内数据绑定一组radiobutton控件的正确方法.
我的业务对象有一个整数属性,我想对4个radiobuttons进行数据绑定(其中每个都代表值0 - 3).
我目前正在绑定一个presenter对象,它作为表单和业务对象之间的绑定器,我现在的方式是拥有4个独立的属性,每个属性都绑定这些值(我使用INotifyPropertyChanged) ,但不包括这里):
Private int _propValue;
Public bool PropIsValue0
{
get { return _propValue == 0; }
set
{
if (value)
_propValue = 0;
}
}
Public bool PropIsValue1 { // As above, but with value == 1 }
Public bool PropIsValue2 { // As above, but with value == 2 }
Public bool PropIsValue3 { // As above, but with value == 3 }
Run Code Online (Sandbox Code Playgroud)
然后我将每个单选按钮绑定到它们各自的属性,如上所述.
这对我来说似乎不对,所以任何建议都受到高度赞赏.
我有三个radiobuttons,我想在屏幕上均匀地隔开它们.当我使用时android:layout_weight="1",按钮在屏幕上伸展.那么,如何在不同的屏幕尺寸上进行缩放,每个屏幕之间的空间大小相同?
<RadioGroup
android:id="@+id/auton_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:layout_below="@id/clear_fields"
>
<RadioButton
android:id="@+id/auton_radio_1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/auton_col"
android:layout_weight="1"
/>
<!-- android:layout_marginRight="380dp" -->
<RadioButton
android:id="@+id/auton_radio_2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/auton_col"
android:layout_weight="1"
/>
<RadioButton
android:id="@+id/auton_radio_3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/auton_col"
android:layout_weight="1"
/>
</RadioGroup>
Run Code Online (Sandbox Code Playgroud) 我是android领域的新手..
我正在开发一个基于测验的应用程序.当用户打开此应用时,将有1个问题和4个选项(单选按钮)单选按钮将被取消选中但是当用户回答1个任务并且当他去下一个任务单选按钮时问题将被检查.我想取消选中/重置每个问题的单选按钮.我该怎么做?
预先感谢...
answ1=new ArrayList<String>(new ArrayList<String>(answ1));
btn_practice1.setText(answ1.get(0));
btn_practice2.setText(answ1.get(1));
btn_practice3.setText(answ1.get(2));
btn_practice4.setText(answ1.get(3));
btn_practicerg.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton radioButton = (RadioButton)group. findViewById(checkedId); //line 262
String temp = radioButton.getText().toString();
switch(btn_practicerg.getCheckedRadioButtonId()){
case R.id.RB1:
if (btn_practice1.isChecked()){
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB2:
if (btn_practice2.isChecked()){
btn_practice1.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB3:
if (btn_practice3.isChecked()){
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice4.setChecked(false);
}
break;
case R.id.RB4:
if (btn_practice4.isChecked()){
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
}
break;
default:
btn_practice1.setChecked(false);
btn_practice2.setChecked(false);
btn_practice3.setChecked(false);
btn_practice4.setChecked(false);
}
ImageView nextBtn = (ImageView) findViewById(R.id.nxt_btn);
nextBtn.setOnClickListener(new …Run Code Online (Sandbox Code Playgroud) 我被迫使用IE8(8.0.7601.17514),我有这个简单的页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<form action=".">
<input type="radio" name="rad" value="1" onchange="alert(1);"/>
<input type="radio" name="rad" value="0" onchange="alert(0);" checked="checked"/>
</form>
<a href="http://google.com">some dummy link</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我期望的是,当选择第二个单选按钮时,单击第一个单选按钮将立即发出警报.这在FF中运行良好.
实际发生的是,当我点击第一个收音机时,没有任何反应.然后,当元素模糊时(例如,我点击其他地方,另一个无线电,页面中的某些链接等),然后提出警报.
这有解决方法吗?
编辑:
显然这种行为完全符合W3C规范
更改
当控件失去输入焦点并且自获得焦点后其值已被修改时,会发生更改事件.此事件对INPUT,SELECT和TEXTAREA有效.元件.
(感谢@ mu-is-too-short).
解决方法是添加onclick blur + focus:
function radioClick()
{
this.blur();
this.focus();
}
<input type="radio" name="rad" value="1" onclick="radioClick" onchange="alert(1);"/>
Run Code Online (Sandbox Code Playgroud) 我Activity在android中写了一个我在RadioGroup下有两个单选按钮的地方.默认情况下会检查其中一个.但我不能在onCreate方法中触发事件,以便我可以做一些事情.在onCheckedChanged点击时运行良好.
RadioGroup ItemtypeGroup = (RadioGroup) findViewById(R.id.rechargeItemtype);
RadioButton providerRadio = (RadioButton) findViewById(R.id.a);
providerRadio.performClick();
ItemtypeGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged (RadioGroup group,int checkedId){
Log.d("chk", "id" + checkedId);
if (checkedId == R.id.a) {
//some code
} else if (checkedId == R.id.b) {
//some code
}
}
});
Run Code Online (Sandbox Code Playgroud) 如果我第一次设置一个单选按钮,它可以正常工作.但如果我通过调用((RadioButton)findViewById(R.id.ID))取消选择它.setChecked(false); 然后,即使我尝试通过调用setChecked(true)来选择它也不会工作,除非用户从屏幕上选择它.
有没有人碰到过这个?还是只有我?
if(Val != null){
if( ((RadioButton) findViewById(R.id.ID1)).getText().toString().trim().equals(Val))
((RadioButton) findViewById(R.id.ID1)).setChecked(true);
else if(((RadioButton) findViewById(R.id.ID2)).getText().toString().trim().equals(Val))
((RadioButton) findViewById(R.id.ID2)).setChecked(true);
}
else {
((RadioButton) findViewById(R.id.ID1)).setChecked(false);
((RadioButton) findViewById(R.id.ID2)).setChecked(false);
}
Run Code Online (Sandbox Code Playgroud)
如果else部分至少执行一次,那么一切都会变得混乱.当我进入调试器时,我可以看到执行进入正确的路径并将其设置为true.它只被执行一次,我检查了一下.而且我没有在代码的任何其他部分将其重置为false.
我以前把枚举绑定到单选按钮,我一般都明白它是如何工作的.我使用了这个问题的替代实现:如何将RadioButtons绑定到枚举?
我想生成一个自定义类型的运行时枚举集,而不是枚举,而是将它们作为一组单选按钮呈现.我已经得到了一个视图,它使用一个运行时枚举的集合ListView,并绑定到ItemsSource和SelectedItem属性,因此我ViewModel可以正确连接.现在我正试图从a切换ListView到a ItemsControl与单选按钮.
就我而言:
<Window.Resources>
<vm:InstanceToBooleanConverter x:Key="InstanceToBooleanConverter" />
</Window.Resources>
<!-- ... -->
<ItemsControl ItemsSource="{Binding ItemSelections}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type vm:ISomeType}">
<RadioButton Content="{Binding Name}"
IsChecked="{Binding Path=SelectedItem, Converter={StaticResource InstanceToBooleanConverter}, ConverterParameter={Binding}}"
Grid.Column="0" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
InstanceToBooleanConverter具有与EnumToBooleanConverter其他问题相同的实现.这似乎是正确的,因为它似乎只是调用Equals方法:
public class InstanceToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.Equals(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) …Run Code Online (Sandbox Code Playgroud) 我在一组中有两个单选按钮,我想检查单选按钮是否已使用JQuery检查,如何?
让我们想象我有:
<RadioButton GroupName="Group1" IsChecked="{Binding Path=RadioButton1IsChecked}" />
<RadioButton GroupName="Group1" IsChecked="{Binding Path=RadioButton2IsChecked}" />
Run Code Online (Sandbox Code Playgroud)
然后在我的数据源类中,我有:
public bool RadioButton1IsChecked { get; set; }
public bool RadioButton2IsChecked { get; set; }
public enum RadioButtons { RadioButton1, RadioButton2, None }
public RadioButtons SelectedRadioButton
{
get
{
if (this.RadioButtonIsChecked)
return RadioButtons.RadioButton1;
else if (this.RadioButtonIsChecked)
return RadioButtons.RadioButton2;
else
return RadioButtons.None;
}
}
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式将我的单选按钮直接绑定到SelectedRadioButton属性吗?我真的只需要RadioButton1IsChecked和RadioButton2IsChecked属性来计算选定的单选按钮.
在我的网页中,我放置了一些单选按钮.但这些按钮无法正常工作.我可以检查多个按钮.
码:
<label for="abc" style="margin-top:-20px;margin-left:40px">xyz</label>
<input type="radio" id="abc" name="abc" >
<label for="bcd" style="margin-top:-20px;margin-left:40px">abc</label>
<input type="radio" id="bcd" name="bcd" >
<label for="efg" style="margin-top:-20px;margin-left:40px">ccc</label>
<input type="radio" id="efg" name="efg" >
Run Code Online (Sandbox Code Playgroud)
我只想检查一个按钮.请任何人帮助我.
radio-button ×10
android ×4
radio-group ×3
html ×2
javascript ×2
wpf ×2
binding ×1
c# ×1
cellspacing ×1
clear ×1
data-binding ×1
jquery ×1
mvvm ×1
uncheck ×1
winforms ×1