Android:OnCLickListener没有反应
我的Android:OnCLickListener没有反应,android,Android,我的活动中有三个按钮,其中有三个独立的onClickListeners设置,就像我以前做过很多次一样。但其中一位听众对点击事件没有反应,我也不知道为什么。以下是代码段: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edit_reminder_2); //References to layout r
活动中有三个按钮
,其中有三个独立的onClickListeners
设置,就像我以前做过很多次一样。但其中一位听众对点击事件没有反应,我也不知道为什么。以下是代码段:
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代码的一部分,我在其中定义了我的按钮
:
<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>
请删除下一个按钮代码中的android:enabled=“false”,以便使用下一个按钮
<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" />
我们可以查看指定按钮的活动的xml描述吗?您发布的代码应该有效。我猜您没有在XML文件中正确分配id,或者您需要清理和重建项目。另外,您是在扩展按钮
类,还是这些按钮只是普通的按钮
?我添加了xml代码。edit2Back按钮可以工作,但edit2Next没有发送:(真奇怪哦,天啊,现在我注意到了,我已经启用了设置为false!:(为这个愚蠢的问题感到抱歉!无论如何谢谢你的帮助;)已经完成了,我不敢相信我没有注意到。我想这就是我对代码过度循环的结果。