[英]Switch form Widget - GridView Android
I have add an Gridview
with Imageview
, TextView
. 我已经添加了
Gridview
与Imageview
, TextView
。 It is working perfectly fine. 运行正常。 Now i want to add
on/off
button . 现在我想添加
on/off
按钮。 I choose Switch. 我选择开关。 It is also working fine.
它也工作正常。 I need to set click/checkchanged action.
我需要设置点击/选中更改的操作。 But i face one issue.
但是我面临一个问题。
First i tried with onCheckChanged
Listener It is working. 首先,我尝试使用
onCheckChanged
Listener。 But the problem was when i try to scroll GridView
checkchanged Listener called. 但是问题是当我尝试滚动
GridView
checkchanged Listener时被调用。
So 所以
I try to another option onclick
Listener. 我尝试另一个选项
onclick
侦听器。 It is also working. 它也正在工作。 Here the problem was when i swipe switch click action not triggered.
这里的问题是当我滑动开关单击动作未触发时。
I try another one option. 我尝试另一种选择。 That is
onTouch
Listener. 那就是
onTouch
Listener。 It is not working. 它不起作用。 The reason was when i touch action called multiple times.
原因是当我多次触摸动作时。
How to handle switch in GridView
? 如何
handle switch in GridView
? Please anyone help me. 请任何人帮助我。
For example you can use form checkBox
: 例如,您可以使用表单
checkBox
:
CheckBox chk = (CheckBox) findViewById(etc.....);
chk.setOnClickLictenetr(new oclickLictener(){
@Override
public void onclick(View view){
CheckBox chekbox = (CheckBox) view;
for example this is your structure===> item.done = chekbox.isChecked();
}
});
If you scrolling , you will have your checked. 如果滚动,则将进行检查。
I found the solution that is disable switch. 我找到了禁用开关的解决方案。 Little bit confusing .
有点混乱。 But the solution was
但是解决方案是
Step 1: 第1步:
Implement setOnTouchListener 实现setOnTouchListener
ex: 例如:
switchButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return event.getActionMasked() == MotionEvent.ACTION_MOVE;
}
});
Step 2: 第2步:
After step 1. We are free to implement onclickListener. 步骤1之后。我们可以自由实现onclickListener。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.