Note that there are some explanatory texts on larger screens.

plurals
  1. POdisable button in fragment from main activity
    primarykey
    data
    text
    <p>I have 3 buttons in a fragment and I want to disable them from the main activity. I have tried to use the bundle option before replace() newfragment but it created other issues. Can a button in a fragment be casted to a main activity ? Something like this. I get the error cannot cast but my entries are incorrect. </p> <pre><code> RedUp = (ButtonControls) getFragmentManager().findFragmentById(R.id.btnRedUP); </code></pre> <p>Here is my main.xml this holds the fragment called rgb_controls</p> <pre><code> &lt;FrameLayout android:id="@+id/rgb_controls" android:layout_width="390dp" android:layout_height="match_parent" android:layout_marginLeft="550dp" android:layout_marginTop="10dp" &gt; &lt;/FrameLayout&gt; </code></pre> <p>Here is the button in the fragment xml called button_controls.xml</p> <pre><code> &lt;Button android:id="@+id/btnRedUP" android:layout_width="80dp" android:layout_height="80dp" android:layout_marginLeft="10dp" android:layout_marginTop="80dp" android:text="UP" android:textSize="30dp" /&gt; </code></pre> <p>Here is the fragment actiivty </p> <pre><code> public class ButtonControls extends Fragment { public Button RedUp, RedDn, GreenUp, GreenDn, BlueUp, BlueDn; View view; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.button_controls, container, false); RedUp = (Button) view.findViewById(R.id.btnRedUP); return view; } } </code></pre> <p>Fragment is added using the replace()</p> <pre><code> Fragment ButtonFragment = new ButtonControls(); ButtonFragment.setArguments(bundle); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.rgb_controls, ButtonFragment).addToBackStack(null).commit(); </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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