2012-02-04 39 views
1

我有一個按鈕如何使按鈕按一次,然後不再按?

<Button 
    android:layout_above="@id/choice2" 
    android:layout_centerHorizontal="true" 
    android:textColor="#FFFF00" 
    android:textSize="25sp" 
    android:gravity="center" 
    android:background="@drawable/loginbutton" 
    android:layout_height="30dp" 
    android:layout_width="fill_parent" 
    android:layout_marginBottom="15dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:text="@string/q1a1" 
    android:id="@+id/choice1"> 
</Button> 

,當你按下這個按鈕,它增加了10到計數器/得分門將。如何讓這個按鈕能夠按下一次,但之後不能再按下?用戶可以作弊並多次按下該按鈕以添加更多分數。

回答

7

,像這樣做:

final Button choice1 = (Button) findViewById(R.id.choice1); 
    choice1.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      choice1.setEnabled(false); 
     } 
    }); 
+0

另外一個沒有工作,但是這適合我的目的,運作良好。謝啦! – codesomethin 2012-02-04 21:41:36

0

按下時禁用按鈕(在代碼中也處理按鈕的「正常」操作)。

3

您可以隱藏或您onCreate方法禁用它

Button mybutton; 

    mybutton.setVisibility(View.GONE); // hide it 
    mybutton.setClickable(false); // disable the ability to click it 
相關問題