Use button in fragments
<p>I have to increment/decrement a text in a Textview with two button (one increment,one decrement). I am doing all in a Fragment and I noticed that is a little bit different work in them. </p>

<p>These are buttons and textview</p>

<pre><code>&lt;Button
        android:layout_width="36dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="90dp"
        android:text="-"
        android:id="@+id/minus"
        android:onClick="decrement"
        /&gt;
        &lt;TextView
        android:layout_width="36dp"
        android:layout_height="match_parent"
        android:paddingTop="15dp"
        android:textSize="18sp"
        android:id="@+id/text"
        android:textAlignment="center"
        android:texr="stats"/&gt;
         &lt;Button
        android:layout_width="36dp"
        android:layout_height="match_parent"
        android:text="+"
        android:id="@+id/plus"
        android:onClick="increment"
        /&gt;
</code></pre>

<p>This is the Fragment's code</p>

<pre><code>public class MyFragment extends Fragment {
int stat= 0;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    return inflater.inflate(R.layout.fragment_my_fragment, container, false);
}
public void increment(View view){
    stat= stat+ 1;
    displaytext();
}

public void decrement(View view){
        stat = stat - 1;
        displaytext();
}

public void displaytext(){
    TextView textViewevstat = (TextView) getView().findViewById(R.id.text);
    textViewevstat.setText("" + stat);
}
}
</code></pre>

<p>It don't take me syntax errors or similar but ,in the emulator ,the app crash when i press one button.
I have to remake all this passage other times but ,in this case, i think is sufficient to change ids and method's name.</p>