我有按鈕「saveStats」似乎不接受點擊。按鈕不可點擊
在模擬器上沒有點擊動畫。
我試圖做乾淨和重新啓動Eclipse,沒有工作。
我也有CheckBox小部件,工作正常,只有按鈕不工作。這裏是我的代碼:
感謝幫助:)
Button saveStats;
CheckBox ageCheck, heightCheck, weightCheck, fatCheck;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.set_personal_data);
saveStats = (Button) findViewById(R.id.saveStats);
ageCheck = (CheckBox) findViewById(R.id.checkBoxAge);
heightCheck = (CheckBox) findViewById(R.id.checkBoxHeight);
weightCheck = (CheckBox) findViewById(R.id.checkBoxWeight);
fatCheck = (CheckBox) findViewById(R.id.checkBoxFat);
saveStats.setOnClickListener(this);
ageCheck.setOnClickListener(this);
heightCheck.setOnClickListener(this);
weightCheck.setOnClickListener(this);
fatCheck.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.saveStats:
{
Toast.makeText(this, "working", Toast.LENGTH_LONG).show();
return;
}
case R.id.checkBoxAge:
{
if(ageCheck.isChecked())
Toast.makeText(this, "ok", Toast.LENGTH_LONG).show()
return;
}
////
////
////
////....
按鈕XML代碼:
<Button
android:id="@+id/saveStats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:text="save" />
我並覆蓋其不工作。爲什麼按鈕不工作和CheckBox工作? – tomer 2013-05-14 15:34:11
你需要將你的'return'改爲'break'。返回用於退出一個方法並返回'onClick()'中'void'的一些值。 'break'用於退出'switch'。即使這確實起作用,如果您決定在該方法中添加行爲,則無論點擊了哪個「視圖」,該代碼都不會運行 – codeMagic 2013-05-14 15:36:38
返回完成該方法,因此交換機也會結束。 我沒有得到返回前的代碼。 – tomer 2013-05-14 15:39:31