I have made an app, where the user presses a button to lead onto another activity, but I only want the user to press this button 5 times in total. I tried the below code, however it doesn't stop the user pressing the button more than 5 times, so I'm guessing the app needs to somehow remember the clicks?
public void FoodClicks(View view){ if(this.counter == 5){ this.counter ++; } else { Button btn = (Button)findViewById(R.id.button); btn.setEnabled(false); } } ActivityMain.xml:
<Button android:id="@+id/button" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="38dp" android:text="@string/addmeal" />