friend ,
我正在尝试编写一个在 ChildView 中使用单选复选框的 ExpandableListView。 而且我无法理解如何在 ExpandableListView 的 OnChildClickListener() 中将其他 CheckBox 设置为“false”。这是我的代码:
ExpListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
CheckBox cb = (CheckBox) v.findViewById(R.id.checkbox);
if (cb.isChecked()) {
} else {
cb.setChecked(true);
//Here somehow I must set all other checkboxes to false.
//Is it possible?
}
return false;
}
});
这是 ChildView 的 xml:
<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/textChild"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:textColor="@android:color/white"
android:layout_weight="1"
/>
<CheckBox android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
android:layout_gravity="right"
android:visibility="visible"
/>
</LinearLayout>
最佳答案
如果您只想选择一个复选框,您可以将选中的复选框存储在一个变量中 CheckBox checkedBox; .当 CheckBox被点击,你可以按照
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
CheckBox last = checkedBox //Defined as a field in the adapter/fragment
CheckBox current = (CheckBox) v.findViewById(R.id.checkbox);
last.setCheked(false); //Unchecks previous, checks current
current.setChecked(true); // and swaps the variable, making
checkedBox = current; // the recently clicked `checkedBox`
return false;
}
不过,我不确定这是否适用于 Android 的 View 回收系统,但值得一试。
如果需要多选,可以展开checkedBox进入List<CheckBox> ,并在每次需要取消选中框时对其进行迭代。
如果你需要存储一些额外的数据(你很可能需要),你可以创建一个 holder 类,例如
class CheckBoxHolder{
private CheckBox checkBox:
private int id;
public CheckBoxHolder(CheckBox cb, int id){
this.checkBox = cb;
this.id = id;
}
// Getter and/or setter, etc.
}
关于Android ExpandableListView 在 ChildView 有单选 CheckBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19293903/
我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模
我有一个带有channel列的Campaign模型。此channel将存储通过复选框选择的结果的序列化数组。这是模型..app/models/campaign.rbclassCampaignapp/controllers/compaigns_controller.rbclassCampaignsController带有复选框的表单部分..views/campaigns/_target.rb......我在将这些结果保存在Campaign对象中时遇到问题。非常感谢任何帮助。 最佳答案 首先,您提到列名称是channel,但是您在Cam
我目前正在使用RSpec编写一个表单测试,我想知道我将如何选择一个单选按钮,给出下面的表单:我希望我的测试看起来像这样:describe"withvalidoptionsselected"dobeforedo#CODETOSELECTARADIOBUTTONclick_button"SAVE"endend 最佳答案 describe"withvalidinfo"dobeforedochoose('True')click_button"CreateSetlist"end...end我必须为单选按钮分配一个ID才能正常工作额外引用文档:
使用Simple_form2.0.2使用HAML的简单表单代码:=f.input:remember_me,as::boolean,inline_label:'Rememberme'但是它呈现了这个:RemembermeRememberme如何删除呈现的第一个标签,以便我只有内联标签? 最佳答案 您可以使用:=f.input:remember_me,as::boolean,inline_label:'Rememberme',label:false 关于ruby-简单形式:Removeout
类似于这个问题:CheckboxesonRails在RubyonRails中制作与特定问题相关的单选按钮的正确方法是什么?目前我有:Theme:PlainDesertGreenCorporateFunky我还希望能够自动检查以前选择的项目(如果重新加载此表单)。我如何将参数加载到这些参数的默认值中? 最佳答案 如thispreviouspost,稍微扭曲一下:Theme:在哪里@theme=params[:theme] 关于ruby-on-rails-Rails上的单选按钮,我们在Sta
我想让它只在单击单选按钮(选项3)时显示下拉菜单,如果选择1或2,则将其隐藏。完成此操作的最佳方法是什么?我对JavaScript有一点经验,对jQuery几乎没有经验,但它似乎是可行的方法。感谢您的帮助,丹这是我目前拥有的HTML代码:Selection:Option1Option2Option3PleaseSelectFromtheList:TrueFalse 最佳答案 $(document).ready(function(){$("[name=select]").change(function(){//Wheneverther
我想用复选框进行一些自定义,它看起来像这样:所以我将我的自定义复选框包装到React组件中:require('../../less/ck-checkbox.less');varReact=require('react');varCkCheckbox=React.createClass({propTypes:{name:React.PropTypes.string,text:React.PropTypes.string,defaultChecked:React.PropTypes.bool,onChange:React.PropTypes.func},getDefaultProps:fu
我有两个单选按钮我在加载时使用了mootoolwindow.addEvent('domready',function(){varchk="1";if(chk==1){$('edit-gender-0').set('checked',true);}elseif(chk==2){$('edit-gender-1').set('checked',true);}但它根本不起作用。任何帮助将不胜感激......以及任何其他没有if条件的简短解决方案。 最佳答案 您提供的代码工作正常-这是一个测试用例:http://jsfiddle.net/o
我正在尝试使用单选按钮在AngularJS中构建一个颜色配置器,一切似乎都在工作,数据绑定(bind)等等......但是我无法设置默认颜色单选按钮。正如我在文档中看到的那样,如果ng-model与radio值相同,则应该自动检查输入,但我不知道这是否仅适用于字符串而不适用于对象。这是HTML:{{color.name}}Preview:{{thing}}这是JS:functionThingControl($scope){$scope.colors=[{name:"White",hex:"#ffffff"},{name:"Black",hex:"#000000"}]$scope.thi
我创建了三个单选按钮。我想运行一个OnClick函数,要求用户确认所选的单选按钮并告知选中的单选按钮值是什么。此外,如果用户未确认选中的单选按钮,则单选按钮将被取消选择。这是我写过但失败的代码。A1A2A3Javascriptfunctionconfirmation(){if(document.getElementById('a1').checked){ty=document.getElementById('a1').valuevarask=confirm("Youhavechosen"+ty+"asyourtype\nIfyouhavechosentherighttype,Click