- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
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/
我正在尝试使 collectionView 工作,但我不太确定 CollectionView 是否自动启动 fetch 方法,然后使用获取的数据填充 ChildViews。或者这是我需要手动做的事情?
我正在尝试制作一个具有带 2 个 View 的选项卡栏 View 的应用程序。第一个包含一个 tableView。使用第二个,您可以将元素添加到 tableView 中。现在我希望能够在 View 之
我有一个名为 ToDoItem 的核心数据实体。它有 2 个属性:createdAt(日期)和 title(字符串)。实体的 Codegen 是类定义,如下所示: import Foundation
我正在尝试在我的 View Controller 上实现 SwipeGesture。 我目前面临的问题是我无法确定当前显示的 subview Controller 是什么。 swipeGesture
我有以下(简化的)层次结构:UINavigationController -> UIViewController -> UITableViewController。我想在使用 hidesBarsOnS
我正在尝试构建一个应用程序。 我想要的是 expandable List 。 ArrayList 的每个元素也应该是列表的一个元素。 Parenttitle 应该是对象的标题。该对象还包含 Array
在我的项目中,我在这个 View 中有 loginviewcontroller 我在 viewWillAppear 方法中隐藏了 navigationcontroller如果登录成功,我有以下代码 -
我有一个像这样打开 subview 的父 View : ChildViewController *child = [[ChildViewController alloc] initWithNibNam
我是 Backbone 和 Marionette 的新手,并从书中学到了这一点 Getting Started with Backbone Marionette由 Packpub 出版。 我收到的错误
我有一个 ExpandableListView;列表的单个项目(组项目)有一个包含 ToggleButton 的 FrameLayout。我这样做是为了增加按钮的触摸区域。我使用按钮展开它所属的组项的
我试图从嵌入在 scrollView 中的 stackView 中提取一个 View ,然后将所述 View 重新定位在同一位置,但在 View 层次结构中与 scrollView 处于同一级别的另一
这是一个fiddle for this question (确保您的控制台已打开): 基本上,我有一个 Handlebars block View 作为父级,然后循环遍历项目数组并为每个项目创建子 b
我正在尝试将图像添加到工具栏的图像列表中,它是 CMainFrame 的成员 startStopPicture.LoadBitmapW(IDB_STOP_PIC); m_ToolBar.GetTool
我有 ExpandableList,我将其分配给扩展的 BaseExpandableListAdapter。在这里,我实现了 getChildView 方法来为每个 child 设置和返回一个 Vie
friend , 我正在尝试编写一个在 ChildView 中使用单选复选框的 ExpandableListView。而且我无法理解如何在 ExpandableListView 的 OnChildCl
我有一个简单的 RecyclerView,当您在 RecyclerView 中 LongClick 一行时,我会显示一个隐藏的 LinearLayout在那一行。为此,在我的 public overr
我已经阅读了许多关于此内容和 Apple 文档的其他主题,但尚未找到针对我的特定问题的解决方案。 我的应用使用 UITabBarController作为 rootViewController , 在其
在MarionetteJS中,创建CollectionView时,所有 subview 在渲染时都会自动用换行符分隔。我希望特定 CollectionView 中的子项必须按顺序渲染,而无需添加换行符
我正在尝试通过 Internet 为我的答案找到解决方案,但找不到合适的解决方案。我看了这个话题:Android ExpandableListView Child Headers但它对我不起作用。 我
我需要在另一个 View 之上添加一个新 View (带 ViewController)。用户与这个新 View 交互了一段时间,然后我想将其删除。在旧版本的 Xcode 中,我可以将其添加为 sub
我是一名优秀的程序员,十分优秀!