Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should not be directly accessing the state of an input in one fragment from another.</p> <p>It is better to create a activity level variable to save the boolean value indicated by the cb.</p> <pre><code>public boolean lf_ch = false; // default checked state. </code></pre> <p>Initialize the checked state of your cb to the value of your variable.</p> <pre><code>lc.setChecked(context.getActivity().lf_ch); </code></pre> <p>Then change the value of your variable when the checked state changes.</p> <pre><code>lc.setOnCheckedChangeListener(new OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { context.getActivity().lf_ch = isChecked; }}); </code></pre> <p>Then in frag1 you can test the value of If_ch;</p> <pre><code>if(context.getActivity().If_ch){ // Do something } </code></pre> <p>----- EDIT -------</p> <pre><code>@TargetApi(11) public class gamesmodestab extends Activity{ public static Context appContext; public boolean lf_ch=false; public void onCreate(Bundle savedInstanceState){ appContext=this; super.onCreate(savedInstanceState); //Then I declare the fragments and add them In the Frgment were the checkbox is available: @TargetApi(11) public class tabquests extends Fragment{ gamesmodestab gmt = (gamesmodestab) getActivity(); public CheckBox lc, @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)//onCreateView { View V=inflater.inflate(R.layout.tab_quests, container, false); lc=(CheckBox)V.findViewById(R.id.CheckBox01); lc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { gmt.If_ch = isChecked; } }); </code></pre> <p>You will need to define gmt in this class as well.</p> <pre><code>public void onClick(View v) { if(!gmt.lf_ch) { </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload