2012-08-22 104 views
0

我有三個按鈕在我的Activity與三個單獨的onClickListeners設置像我以前做了很多次。但其中一位聽衆對點擊事件沒有反應,我不知道爲什麼。這裏是代碼段:Android:OnCLickListener沒有反應

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.edit_reminder_2); 

    //References to layout resources 
    edit2Back = (Button) findViewById(R.id.edit2Back); 
    edit2Next = (Button) findViewById(R.id.edit2Next); 
    edit2ChangeGPS = (Button) findViewById(R.id.edit2ChangeGPS); 

    //Assigning listeners to Buttons 
    edit2Back.setOnClickListener(listenerBack); 
    edit2Next.setOnClickListener(listenerNext); 
    edit2ChangeGPS.setOnClickListener(listenerChange); 

} 

final OnClickListener listenerNext = new OnClickListener() { 

    public void onClick(View v) { 
     Log.v("edit2Next","Click!"); 
     db.open(); 

     String sName = edit2ReminderName.getText().toString(); 
     String sNote = edit2ReminderText.getText().toString(); 
     int sRadius = Integer.parseInt(edit2Radius.getText().toString()); 
     String sUnits = (String) edit2SpinnerUnits.getSelectedItem(); 
     int sChecked = 0; 
     if (edit2Check.isChecked()) { 
      sChecked = 1; 
     } 

     db.insertReminder(sName, sNote, lat, lon, sRadius, sUnits, sChecked); 

     db.close(); 

     Intent intent = new Intent(context, Reminders.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     startActivity(intent); 
    } 

}; 

所有我的其他聽衆我寫在同一時尚,他們工作得很好,但這一個沒有。我查看了所有的代碼,但找不到原因。監聽器根本不啓動,甚至沒有運行Log.v指令。謝謝你的建議!

編輯:

這是XML代碼,我定義的一部分,我Buttons

<LinearLayout 
    android:id="@+id/edit2ControlLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@color/azure" 
    android:padding="15dp" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/edit2Back" 
     android:layout_height="wrap_content" 
     android:layout_width="0.0dip" 
     android:text="Back" 
     android:background="@drawable/round_button_violet" 
     android:textColor="@color/azure" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:layout_weight="1.0" 
     android:layout_marginRight="5dp" /> 

    <Button 
     android:id="@+id/edit2Next" 
     android:layout_height="wrap_content" 
     android:layout_width="0.0dip" 
     android:text="Next" 
     android:background="@drawable/round_button_violet" 
     android:textColor="@color/azure" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:layout_weight="1.0" 
     android:enabled="false" />   


</LinearLayout> 
+1

我們可以看到指定按鈕的Activity的xml描述嗎? – Hbcdev

+0

您發佈的代碼應該可以工作。我猜你沒有在XML文件中正確分配id,或者你需要清理並重建你的項目。另外,你是在擴展'Button'類,還是隻是普通的'Buttons'? – you786

+0

我添加了xml代碼。 edit2Next doesent :(但它真的很奇怪 –

回答

1

請刪除的android:啓用=「假」,在你的下一個按鈕的代碼,以便下一步按鈕。

<Button 
    android:id="@+id/edit2Next" 
    android:layout_height="wrap_content" 
    android:layout_width="0.0dip" 
    android:text="Next" 
    android:background="@drawable/round_button_violet" 
    android:textColor="@color/azure" 
    android:paddingTop="10dp" 
    android:paddingBottom="10dp" 
    android:layout_weight="1.0" 
    android:enabled="false" /> 
+0

已經做到了,我不能相信我沒有注意到這一點,我想這就是我得到的過度循環代碼。 –