Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RadioGroup setOnCheckedChangeListener不能与RadioButton setOnTouchListener一起使用_Java_Android - Fatal编程技术网

Java RadioGroup setOnCheckedChangeListener不能与RadioButton setOnTouchListener一起使用

Java RadioGroup setOnCheckedChangeListener不能与RadioButton setOnTouchListener一起使用,java,android,Java,Android,我有一个里面有单选按钮的放射组。我的问题是当我检查radiobutton listener是否工作时。当我删除radiobutton touchlistener事件时,它会工作 final RadioGroup RGroup = (RadioGroup) view.findViewById(R.id.RGroup); RGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

我有一个里面有单选按钮的放射组。我的问题是当我检查radiobutton listener是否工作时。当我删除radiobutton touchlistener事件时,它会工作

final RadioGroup RGroup = (RadioGroup) view.findViewById(R.id.RGroup);

    RGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
    {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            RadioButton checkedRadioButton = (RadioButton) group.findViewById(checkedId);
            boolean isChecked = checkedRadioButton.isChecked();
            if (isChecked)
            {
                checkedRadioButton.setButtonDrawable(R.drawable.ic_check_black_24dp);
            }
        }
    });
当我删除下面的代码时,此代码有效

 button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                    int colorFrom = v.getResources().getColor(android.R.color.transparent);
                    int colorTo = v.getResources().getColor(R.color.colorAnswer);
                    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
                    colorAnimation.setDuration(1000); // milliseconds
                    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                        @Override
                        public void onAnimationUpdate(ValueAnimator animator) {
                            button.setBackgroundColor((int) animator.getAnimatedValue());
                        }

                    });
                    colorAnimation.start();
                return true;
            }
        });
单选按钮的布局

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_below="@id/slide_question"
    android:layout_marginTop="@dimen/pad_7dp"
    android:id="@+id/RGroup">

<android.support.v7.widget.AppCompatRadioButton
    android:id="@+id/radioButton1"
    android:layout_width="match_parent"
    android:layout_marginBottom="@dimen/pad_5dp"
    android:padding="@dimen/pad_10dp"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    app:fontFamily="@font/ubuntu"
    android:textColor="@color/colorBlackText"
    app:buttonTint="@color/colorPrimary"
    android:text="RadioButton" />
<android.support.v7.widget.AppCompatRadioButton
    android:id="@+id/radioButton2"
    android:layout_width="match_parent"
    android:layout_marginBottom="@dimen/pad_5dp"
    android:padding="@dimen/pad_7dp"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    app:fontFamily="@font/ubuntu"
    android:textColor="@color/colorBlackText"
    app:buttonTint="@color/colorPrimary"
    android:text="RadioButton" />

</RadioGroup>


可能监听器冲突

是的,这是因为监听器冲突。当您当时应用touchListener时,它会停止组的checkChangeListener以获取事件

仍然可以从onTouch方法中尝试
return false
,检查它是否工作。 尝试后发布行为。

检查此项-