我已经创建了一个应用程序,用户按下一个按钮导致其他活动,但我只希望用户总共按下此按钮5次。我尝试了下面的代码,但是它不会停止用户按下按钮超过5次,所以我猜应用程序需要以某种方式记住点击次数?限制点击次数
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" />
您如何在按钮中使用FoodClicks(View)?你可以发布你的布局xml吗? – 2015-03-02 15:16:27
你在哪里使用这种方法在片段或活动? – 2015-03-02 15:17:33
看看http://stackoverflow.com/questions/4022830/saving-state-between-activities/4022933#4022933 – Joel 2015-03-02 15:17:50