내 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>
버튼을 지정하는 활동의 xml 설명을 볼 수 있습니까? – Hbcdev
게시 한 코드가 작동해야합니다. XML 파일에 ID를 올바르게 할당하지 않았거나 프로젝트를 정리하고 다시 작성해야한다고 생각합니다. 또한'Button' 클래스를 확장하고 있습니까, 아니면 그냥 정상적인'Buttons'입니까? – you786
xml 코드를 추가했습니다. edit2Back 버튼은 작동하지만 edit2Next는 다음과 같이합니다. (정말 이상합니다. –