1

I am trying to check whether the radio button is checked or not. On basis of that, I will trigger some actions. I searched and found out "isChecked" is the method to do so. I use that method but the android studio says Cannot Resolve symbol 'isChecked()'.

enter image description here

<CheckBox
        android:id="@+id/cream"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:checked="false"

        android:paddingLeft="26dp"
        android:text="Whipped Cream"
        android:textSize="16sp" />

final CheckBox box = (CheckBox) findViewById(R.id.cream);
     if (box.isChecked())
     {
    box.setChecked(false);
}

Thank you in advance.

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

Having a similar problem now, with v

final CheckBox whipped_cream_variable = (CheckBox) findViewById(R.id.whipped_cream);
boolean whipped_cream_has = whipped_cream_variable.isChecked();
Log.v("MainActivity", "Has whipped cream:" + whipped_cream_has);
Cena
  • 3,316
  • 2
  • 17
  • 34
Jaykumar
  • 137
  • 2
  • 12
  • did you import whats needed? Did you try cleaning and rebuilding the project? – Dan Baruch Oct 26 '20 at 13:11
  • Till now , I have imported following import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.CheckBox; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; – Jaykumar Oct 26 '20 at 13:32
  • I just copied your code and it's working fine here. Did you try exiting your framework and opening it again? Cleaning project and rebuilding it? – Dan Baruch Oct 26 '20 at 13:34
  • It worked Dan Baruch . Thank you for it. Now I am having similar problem , Now with "v" – Jaykumar Oct 26 '20 at 13:41
  • Glad it's working. Not sure what other problem you are having? – Dan Baruch Oct 26 '20 at 13:43
  • I see now your new problem, did you import what's needed here as well? – Dan Baruch Oct 26 '20 at 13:47
  • I have import android.util.Log; can you suggest me what else i need to import because i am new to android. – Jaykumar Oct 26 '20 at 13:55
  • That's all you need to import. What error are you getting exactly? cant resolve symbol of v? I'd say that's rather weird. What's your framework? Android Studio? – Dan Baruch Oct 26 '20 at 13:59
  • After trying to cut that Log.v("MainActivity", "Has whipped cream:" + whipped_cream_has); in trigger button the error gone. I searched about it and here i got the solution https://stackoverflow.com/questions/16987788/android-studios-doesnt-understand-log-function – Jaykumar Oct 26 '20 at 14:03
  • Thanks Dan Baruch for giving me advice to solve the problem . – Jaykumar Oct 26 '20 at 14:04
  • Sure thing, glad you got it working. Since you are rather new, I'd suggest you read some android guides to get started which can be found here https://developer.android.com/guide – Dan Baruch Oct 26 '20 at 14:05

1 Answers1

0

Dan Baruch solved the problem

  1. try cleaning and rebuilding the project and
  2. Try to put the statement in the trigger button
Jaykumar
  • 137
  • 2
  • 12