问题描述
目标:我试图创建每行2复选框的UI,每行分隔为几个部分。我已经包括下面的用户界面的屏幕截图。
Goal: I am trying to create a UI with 2 checkboxes per line, each line seperated into sections. I've included a screenshot of the UI below.
目前的做法:我使用的是ExpandableListView并与onChildClick HANDELING数据
Current approach: I am using an ExpandableListView and handeling the data with an onChildClick.
问题:当你点击一个复选框,它不会触发onChildClick或其他任何东西。点击复选框以外的任何位置将触发此事件。
Problem: When you click a checkbox, it does not trigger onChildClick or anything else. Clicking anywhere outside of the checkbox will trigger this event.
研究:有很多的建议设置Android的线程:可调焦=假,但不为我改变什么。我也可获得焦点设置为false,在我的UI每一个元素。
Research: There are lots of threads that suggest setting android:focusable="false", but that doesn't change anything for me. I have focusable set to false for every element in my UI.
复制:我运行的,其中包括安卓code:可聚焦=假。我根据很多上比如我的code,而且如果我能得到它的工作使用codeBase的,我相信我可以得到它在我的工作。
Reproduction: I have the exact same problem running the code from this article without modification, which includes android:focusable="false". I based a lot of my code on that example, and If I can get it working using that codebase, I'm sure I can get it working in mine.
推荐答案
我想这是因为该复选框消耗的情况下,它不会转发到列表项。
I think it's because the checkbox consumes the event and doesn't forward it to the list item.
如果你想获得箱子上点击就可以OnClickListener添加到在getView()名单适配器盒。
If you want to get the click on the boxes you can add OnClickListener to the boxes in the getView() of the list adapter.
我理解你的权利,盒子至少得到确认?如果你不需要定制行为,你如果复选框被选中正好可以阅读或不是当你提交列表中(或者其他的检查框你的下一个步骤)。
I understand you right, the box is at least getting checked? If you don't need custom behaviour you just can read if the box is checked or not when you "submit" the list (or whatever is your next step of checking boxes).
阅读意见后,这里是添加了一些新的code例如:
After reading comments, here is your code example with some additions:
@Override
public View getView(final int pos, final View convView, ViewGroup parent) {
//initialize convView, define other local variables, etc.
CheckBox cb = (CheckBox) convView.findViewById(R.id.mycheckbox);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d("ElistCBox2", "listitem position: " + pos);
}
});
return convView;
}
请注意,你必须使用最后
修改为您在匿名类中使用,否则,你得到一个编译错误的变量。
Note that you have to use final
modifier for the variables which you use in the anonymous class, otherwise you get a compiler error.
这篇关于安卓:复选框ExpandableListView不触发onChildClick甚至可聚焦= FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!