Android: Changing the contents of a Text View using a radio button - java

So, I am trying to write code that will show that Radio Button clicks register. Ideally, when a radio button is chosen, the contents of a TextView will change. To start, I have a radio button for 'North'. When North is checked, the contents of the TextView will become 'North'. I know there are action listeners involved, but I am not familiar with Java. This will surely pop my Java cherry. That being said, the code I have written is not working. Can anyone tell me if I am on the right track, or offer some suggestions? Note, this is not for a class assignment. This is for a very open ended class project that I am working on with another person.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onRadioButtonClicked(View v){
TextView text = (TextView)findViewById(R.id.text);
RadioButton N = (RadioButton) findViewById(R.id.north);
//evaluates 'checked' value of radio button
boolean checked = ((RadioButton) v).isChecked();
if(N.isChecked () ){
text.setText("N");
}
}
}

To use RadioButton properly you'd better group a bunch of RadioButtons into a set, named RadioGroup.
<RadioGroup
android:id="#+id/rg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="#+id/rg1_rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="North" />
<RadioButton
android:id="#+id/rg1_rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="South" />
<RadioButton
android:id="#+id/rg1_rb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whatever" />
</RadioGroup>
The critical part is that you have to set unique android:id for each RadioButtons, or they won't work!
Next, find RadioButtons from your XML.
RadioButton rb1, rb2, rb3;
rb1 = (RadioButton) findViewById(R.id.rg1_rb1);
rb2 = (RadioButton) findViewById(R.id.rg1_rb2);
rb3 = (RadioButton) findViewById(R.id.rg1_rb3);
Finally, prepare a RadioButton.OnClickListener class instance and attach it to RadioButtons.
View.OnClickListener optionOnClickListener
= new View.OnClickListener() {
public void onClick(View v) {
TextView tv = (TextView) findViewById(R.id.textview);
String str = null;
// you can simply copy the string of clicked button.
str = ((RadioButton)v).getText().toString();
tv.setText(str);
// to go further with check state you can manually check each radiobutton and find which one is checked.
if(rb1.isChecked()) {
// do something
}
if(rb2.isChecked()) {
// do something
}
if(rb3.isChecked()) {
// do something
}
}
};
rb1.setOnClickListener(optionOnClickListener);
rb2.setOnClickListener(optionOnClickListener);
rb3.setOnClickListener(optionOnClickListener);
// check rb1 by default, if you want.
rb1.setChecked(true);
ADDED:
I'm sorry but I couldn't understand the edited version of my answer, since calling setOnClickListener() inside the View.OnClickLister.OnClick() was somewhat weird to me.
So I rolled back to my original answer.

Try
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.your_radio_group_id);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.north ;
// set text North for your textview here
break;
case R.id.another_radio_button_id:
// do something
break;
}
}
});

Check your xml file. radio button must be inside the radio group for work perfectly.
<RadioGroup
android:id="#+id/Type"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/n"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I am a Blood Donor" />
<RadioButton
android:id="#+id/s"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RadioGroup>
then change in your java file
mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if (i == R.id.s) {
//Your action
} else if (i == R.id.n) {
//Your action
}
}
});
it will work.. :) :)

Okay, so making 'onCheckedChange' the onClick event seemed to do the trick. Thanks for all the help people.

Related

Automatic input before next click input [duplicate]

I know these type of question asked many time .but still nobody gave perfect answer for that.
I have question :
I want to move from EditText1 ** to another **EditText2 .
I had already detect to editText1 but how to move cursor to editText2.?
In short I had to move my cursor position from one editText1 to another EditText2 directly.
I faced this type of issue and found the solution as below.
Here I have two editText, if I press "a", my cursor will move to next step. I used below code for doing it.
final EditText editText = (EditText) findViewById(R.id.editText1);
editText.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v , int keyCode , KeyEvent event) {
EditText editText2 = (EditText) findViewById(R.id.editText2);
// TODO Auto-generated method stub
if (keyCode == event.KEYCODE_A) {
Selection.setSelection((Editable) editText2.getText(),editText.getSelectionStart());
editText2.requestFocus();
}
return true;
}
});
Let me know if you are facing any error regarding this.
For this, all you need to do is...add below two properties to your EditText tag in xml, except the last EditText(In case, you add it to the last EditText also, then the cursor control will again go to the first EditText when you press enter/next from the keypad)
<EditText
.
.
android:singleLine="true"
android:imeOptions="actionNext"
.
.
/>
Hope this helps
Here is a working example, hope this helps.
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some string of text"
/>
<EditText
android:id="#android:id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some string of text"
/>
<Button
android:id="#android:id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
/>
</LinearLayout>
Class:
public class Example extends Activity {
TextView text1;
TextView text2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1 = (EditText) findViewById(android.R.id.text1);
text2 = (EditText) findViewById(android.R.id.text2);
Button button = (Button) findViewById(android.R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Selection.setSelection((Editable) text2.getText(), text1.getSelectionStart());
text2.requestFocus();
}
});
}
}
Set onKeyListener to detect the key pressed on every key pressed checked your condition and when your condition will be fulfilled set edittext property edittext2.requestFocus();
I have tested all the previous code segments, and find all are working fine. But I find just calling "requestFocus()" with the proper edittext object is also working. As per as ques asked, the ans can be:
edittext2.requestFocus();
which is working fine for me. Please correct me if I am wrong.

radioGroup how to hide button android

Hello I want to create a list. On long-press on the toolbar will be shown option to select all and delete selected. I don't know whether I should RadioGroup and hide button or use listView and create own row example and there add radio button.
Default standard android behavior is Contextual Action Bar(which I can interpret) should come when user long presses an item list
as in
One of the many resources are
http://theopentutorials.com/examples/android/listview/android-contextual-action-bar-for-listview-item-deletion-using-actionbarsherlock/
https://androidkennel.org/contextual-toolbar-actionbar-tutorial/
Where I cant get very specific, I can say, usually to achieve your own specific goals creating your own row will prove beneficial to your end goal. Rather then hiding a RadioGroup
I have a little problem with understanding menuInflater. This class instantiate menu XML files into Menu objects. But there set new menu
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { //when this method is going to be made? Menu is int the toolbar and ListView isn't connected with toolbar so which menu I get in the next next line?
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.toolbar_cab, menu); // in this line set a new menu
return true;
}`
To hide RadioButton from RadioGroup is very simple. You just write btnRadio1.setVisibility(View.INVISIBLE);. BUT you have to know this rule: If you have, for example, 4 RadioButtons in RadioGroup, you can make them invisible in reverse order only! I mean the order they are defined in RadioGroup in your layout .xml file. It is impossible to hide btnRadio3 only, and btnRadio4 to be visible! You have to hide btnRadio3 and btnRadio4. Or only btnRadio4. So, if you want to hide 1 button, it is button 4. If you want to hide 2 buttons - they are 4 and 3. If you want to hide 3 buttons they are 4, 3, and 2. All other combinations, simply doesn't work.
Here is code from my Quiz app, where every question may have from 2 to 6 answers. The answers of current question are stored in array of strings answers [].
RadioButton btnAnswer1;
RadioButton btnAnswer2;
RadioButton btnAnswer3;
RadioButton btnAnswer4;
RadioButton btnAnswer5;
RadioButton btnAnswer6;
RadioGroup radioGroup;
// onCreate activity
btnAnswer1 = (RadioButton) findViewById(R.id.btnAnswer1);
btnAnswer2 = (RadioButton) findViewById(R.id.btnAnswer2);
btnAnswer3 = (RadioButton) findViewById(R.id.btnAnswer3);
btnAnswer4 = (RadioButton) findViewById(R.id.btnAnswer4);
btnAnswer5 = (RadioButton) findViewById(R.id.btnAnswer5);
btnAnswer6 = (RadioButton) findViewById(R.id.btnAnswer6);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.clearCheck();
btnAnswer1.setVisibility(View.VISIBLE);
btnAnswer2.setVisibility(View.VISIBLE);
numberOfAnswers = 2; //at least 2 answers
//if 3-d element is empty i.e. 2 answers only
//i.e. buttons 3,4,5,6 must be hidden
if (answers[2].isEmpty()) {
btnAnswer3.setVisibility(View.INVISIBLE);
btnAnswer4.setVisibility(View.INVISIBLE);
btnAnswer5.setVisibility(View.INVISIBLE);
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer3.setVisibility(View.VISIBLE);
numberOfAnswers = 3;
}
if (answers[3].isEmpty()) {
btnAnswer4.setVisibility(View.INVISIBLE);
btnAnswer5.setVisibility(View.INVISIBLE);
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer4.setVisibility(View.VISIBLE);
numberOfAnswers = 4;
}
if (answers[4].isEmpty()) {
btnAnswer5.setVisibility(View.INVISIBLE);
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer5.setVisibility(View.VISIBLE);
numberOfAnswers = 5;
}
if (answers[5].isEmpty()) {
btnAnswer6.setVisibility(View.INVISIBLE);
} else {
btnAnswer6.setVisibility(View.VISIBLE);
numberOfAnswers = 6;
}
And here is xml file:
<ScrollView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_marginLeft="5dip"
android:orientation="vertical">
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/btnAnswer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="#+id/btnAnswer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="#+id/btnAnswer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="#+id/btnAnswer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="#+id/btnAnswer5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<RadioButton
android:id="#+id/btnAnswer6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RadioGroup>
</ScrollView>

Not able to get id of radiobutton via getCheckedRadioButtonId()

I am trying to make a custom dialog box which gives radio buttons to select from n then diplay text of radio button in the textfield. This is what i tried..
My Layout for dialog box is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:id="#+id/rg_carType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<RadioButton
android:id="#+id/rb_hatchD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hatchback(Diesel)" />
<RadioButton
android:id="#+id/rb_hatchP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hatchback(Petrol)" />
<RadioButton
android:id="#+id/rb_sedanD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sedan(Diesel)" />
<RadioButton
android:id="#+id/rb_sedanP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sedan(Petrol)" />
<RadioButton
android:id="#+id/rb_suv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUV" />
</RadioGroup>
<ImageView
android:id="#+id/iv_carType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_toRightOf="#+id/rg_carType"
/>
<Button
android:id="#+id/btn_confirmCar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rg_carType"
android:layout_centerHorizontal="true"
android:background="#drawable/button_2"
android:text="Confirm"
android:textColor="#fff" />
And the function for custom dialog box is
private void diplayCartype() {
final Dialog dialog_car = new Dialog(FinalActivity.this);
final RadioButton rb_select;
RadioGroup rg_carType;
ImageView iv_carType;
Button btn_confirmCar;
String sCar="?";
dialog_car.setTitle("Select Car Type");
dialog_car.setContentView(R.layout.dialog_cartype);
iv_carType=(ImageView)dialog_car.findViewById(R.id.iv_carType);
btn_confirmCar=(Button)dialog_car.findViewById(R.id.btn_confirmCar);
rg_carType=(RadioGroup)dialog_car.findViewById(R.id.rg_carType);
int selected=rg_carType.getCheckedRadioButtonId();
rb_select=(RadioButton)dialog_car.findViewById(selected);
switch(selected)
{
case R.id.rb_hatchD:
iv_carType.setImageResource(R.drawable.hatch_d);
sCar=rb_select.getText().toString();
break;
case R.id.rb_hatchP:
iv_carType.setImageResource(R.drawable.hatch_p);
sCar=rb_select.getText().toString();
break;
case R.id.rb_sedanD:
iv_carType.setImageResource(R.drawable.sedan_d);
sCar=rb_select.getText().toString();
break;
case R.id.rb_sedanP:
iv_carType.setImageResource(R.drawable.sedan_p);
sCar=rb_select.getText().toString();
break;
case R.id.rb_suv:
iv_carType.setImageResource(R.drawable.suv);
sCar=rb_select.getText().toString();
break;
default:
iv_carType.setImageResource(R.drawable.suv);
sCar="default";
}
final String finalSCar = sCar;
btn_confirmCar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
tv_carType.setText(finalSCar);
dialog_car.dismiss();
}
});
dialog_car.show();
}
The problem is that the switch case executes only default condition, that means its not getting id to check. Thanks in advance.. :)
this code work for me
public class RadioButtonFragment extends DialogFragment {
String singleitem;
private int witch;
private MySharedPreferences mySharedPreferences = new MySharedPreferences();
private String[] item = {"Naskh asiatype", "Fajer noori Nastaleeq", "Pak nastaleeq (default)"};
#Override
public void onResume() {
super.onResume();
witch= mySharedPreferences.loadIntPrefs(Constants.RADIO_BUTTON_INDEX_KEY,2,getActivity());
}
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
witch= mySharedPreferences.loadIntPrefs(Constants.RADIO_BUTTON_INDEX_KEY,2,getActivity());
builder.setTitle("please selet any fount").setSingleChoiceItems(item, witch, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
singleitem= item[which];
mySharedPreferences.saveStringPrefs(Constants.FONT_KEY,singleitem,getActivity());
mySharedPreferences.saveintPrefs(Constants.RADIO_BUTTON_INDEX_KEY,which,getActivity());
Toast.makeText(getContext(),"Font is selected"+which,Toast.LENGTH_SHORT).show();
}
});
return builder.create();
}
}
and call to build this fragment
RadioButtonFragment radioButtonFragment = new RadioButtonFragment();
radioButtonFragment.show(getSupportFragmentManager(), RadioButtonFragment_TAG);
You need read the value at the right time (button click). Do this:
btn_confirmCar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
rg_carType=(RadioGroup)dialog_car.findViewById(R.id.rg_carType);
int selected=rg_carType.getCheckedRadioButtonId();
rb_select=(RadioButton)dialog_car.findViewById(selected);
switch(selected)
{
case R.id.rb_hatchD:
iv_carType.setImageResource(R.drawable.hatch_d);
break;
case R.id.rb_hatchP:
iv_carType.setImageResource(R.drawable.hatch_p);
break;
case R.id.rb_sedanD:
iv_carType.setImageResource(R.drawable.sedan_d);
break;
case R.id.rb_sedanP:
iv_carType.setImageResource(R.drawable.sedan_p);
break;
case R.id.rb_suv:
iv_carType.setImageResource(R.drawable.suv);
break;
default:
iv_carType.setImageResource(R.drawable.suv);
sCar="default";
}
if (!sCar.equals("default"))
sCar = rb_select.getText().toString();
tv_carType.setText(sCar);
dialog_car.dismiss();
}
});
dialog_car.show();
}
About getCheckedRadioButtonId()
Returns the identifier of the selected radio button in this group.
Upon empty selection, the returned value is -1.
There is no selected RadioButton at the moment when you are trying to check for selected one.
dialog_car.setContentView(R.layout.dialog_cartype);
// at this point you have newly created view hierarchy and
// RadioGroup has no selected items
iv_carType=(ImageView)dialog_car.findViewById(R.id.iv_carType);
btn_confirmCar=(Button)dialog_car.findViewById(R.id.btn_confirmCar);
rg_carType=(RadioGroup)dialog_car.findViewById(R.id.rg_carType);
// still has no selected items, next call returns -1 as well
int selected=rg_carType.getCheckedRadioButtonId();
You should use getCheckedRadioButtonId() from handler of some extra button (e.g. "OK") to be sure that user has seen your radio buttons and has enough time to select something.
You must use an interface (Listener) for listening to User Inputs. For example you can use RadioGroup.setOnCheckedChangeListener and then place your switch statement in it.
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId){
case R.id.radioButtonId:
// Your Code Here
break;
---
}
}
});
Your current code would statically pick the default values of initially assigned states. Above enhancements would help you handle user inputs dynamically.

2 (or more) button views for the same onClick method

I'm a novice android developper and was wondering:
Could I have 2 buttons to be linked into the same, 1 onClick method (which i'll presumably override to accept 2 extra parameter, int btnId and View targetTextView for instance) in order to decide which button is calling the method and then which TextView text to update?
For Example:
btn1 will update the text on text_view_1
and btn2 will update text_view_2.
Except they we will be linked to the same method:
public void generalOnClick(View view, String btnId, String textViewId){...}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:onClick="btnClick"/>
<TextView
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two"
android:onClick="btnClick"/>
</LinearLayout>
Button Click Function in your Activity
public void btnClick(View view) {
TextView tv = (TextView)view;
int id = tv.getId();
if(id==R.id.one) {
tv.setText("One Clicked");
} else if(id==R.id.two){
tv.setText("Two Clicked");
}
}
set an tag to button and verify it with onClick method that which buttons click event has been triggered , if it doesn't work then follows following trick,
define an common method for the functionality which you are going to execute on button click, make it as common function.
define independent onclick event for both button and then while calling the common function which created above pass some unique param and verify it.
use following code:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View.OnClickListener clickListener = new View.OnClickListener() {
public void onClick(View v) {
if(v.getId().Equals(btn1.getId())){
//do your work here
}
else{
//work for 2nd button
}
};
btn1 = (Button)findViewById(R.id.btn_1);
btn2 = (Button)findViewById(R.id.btn_2);
btn1.setOnClickListener(clickListener);
btn2.setOnClickListener(clickListener);
}

Issues with checkboxes checking other check boxes on App

I am trying to make a checkbox in android studio/java that if checked will result in a subset of other checkboxes checkable and checked.
The developer site says:
abstract void setChecked(boolean checked)
Change the checked state of the view
But this hasn't worked for me.
Current code:
Java:
package crc.cybereye;
public class CreateNew extends Activity {
LinearLayout background;
Button btnBack;
CheckBox checkbox_structural_info;
CheckBox checkbox_years_of;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
background = (LinearLayout) findViewById(R.id.background);
setContentView(R.layout.activity_create_new);
btnBack = (Button) findViewById(R.id.btnBack);
checkbox_years_of = (CheckBox) findViewById(R.id.checkbox_years_of);
checkbox_floors_above = (CheckBox) findViewById(R.id.checkbox_floors_above);
checkbox_structural_info = (CheckBox) findViewById(R.id.checkbox_structural_info);
// setUpIntroCheckBoxes(); // Add change listeners to check boxes
btnBack.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), NewFormActivity.class);
startActivityForResult(intent, 0);
}
});
}
More Java:
public void onCheckboxClicked(View view) {
// Is the view now checked?
boolean checked = ((CheckBox) view).isChecked();
// Check which checkbox was clicked
switch(view.getId()) {
case R.id.checkbox_structural_info:
if (checked){
checkbox_years_of checked.setChecked(true) //ERROR HERE
}
break;
case R.id.checkbox_years_of:
if (checked){
}
break;
XML:
<TableRow android:layout_marginTop="10dp">
<TextView
android:text="#string/structural_info"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
/>
<CheckBox android:id="#+id/checkbox_structural_info"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCheckboxClicked"/>
</TableRow>
<TableRow>
<TextView
android:text="#string/years_of"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
/>
<CheckBox android:id="#+id/checkbox_years_of"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCheckboxClicked"/>
<TableRow>
There is an error saying that it cannot resolve method setChecked(boolean).
My code currently is just trying to get the structural_info checkbox to check the years_of checkbox if it is checked, but I also want to make years_or only checkable if structural_info is checked, I haven't got there yet because I was still stuck on this issue.
Thanks so much for any help in advance.
As requested by the creator of the post, i'm adding the comment as an answer:
You're calling setChecked to checked wich is a boolean variable.
You shoud write:
checkbox_years_of.setChecked(true)
Instead of
checkbox_years_of checked.setChecked(true)

Categories

Resources