Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't need to go through your activity in order to achieve this. Remove the onclick line and add an id for the button in your layout:</p> <pre><code>&lt;Button android:id="@+id/calc_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_singleCalc" /&gt; </code></pre> <p>Then, simply add an OnClickListener to your button within your Fragment. Something like that:</p> <pre><code>private View mRootView; private EditText mEditText; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // If mItem is non-null... if (mItem != null) { if (mItem.title == "Calculation") { // If the title is Calculation, use the calculation layout mRootView = inflater.inflate(R.layout.calculation_layout, container, false); mEditText = (EditText) mRootView.findViewById(R.id.edit_phiD); ((Button)mRootView.findViewById(R.id.calc_button)).setOnClickListener(this); } else { // Otherwise, show the dummy content as text in a TextView mRootView = inflater.inflate(R.layout.fragment_screen_detail, container, false); ((TextView) mRootView .findViewById(R.id.screen_detail)).setText(mItem.title); } } else { mRootView = inflater.inflate(R.layout.fragment_screen_detail, container, false); } return mRootView; } </code></pre> <p>(Your fragment needs to implement OnClickListener for this). Then you'll get a callback on your Fragment, and here's what you do there:</p> <pre><code>public void onClick(View v){ //Retrieve all the information, and set the values in the Calculator String number = mEditText.getText().toString(); double angle = Double.parseDouble(number); Calculator.longCalc(); } </code></pre>
 

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