2
我有一個自定義Android(1.5)標題欄,其中包含一個按鈕。使用活動A中的自定義標題欄,我可以單擊該按鈕,並按預期方式啓動事件OnClickListener
。Android Button OnClick事件觸發多次點擊後
但是,當我從活動A啓動結果的活動B時,可能需要2-3次點擊才能觸發相同的按鈕事件。
這是設置爲活動A中的事件監聽器在onCreate
倍率
setTitleNegativeActionListener(new OnClickListener() {
public void onClick(View v) {
// end this activity
ActivityA.this.finish();
}
});
這是爲活動B從佈局
setTitleNegativeActionListener(new OnClickListener() {
public void onClick(View v) {
setResult(RESULT_CANCELED);
EditClientAddressActivity.this.finish();
}
});
按鈕XML代碼中的代碼
<Button
android:id="@+id/title_button_right"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/nav_button"
android:text="Done" android:textColor="#fff"
android:layout_alignParentRight="true" android:textSize="12dip"
android:textStyle="bold" android:paddingLeft="10dip"
android:paddingRight="10dip" android:layout_centerVertical="true"
android:minWidth="40dip"
android:focusableInTouchMode="false" android:focusable="false" />
看起來好像在活動B中,第一次點擊是將按鈕我nto重點,第二次點擊實際上是按下按鈕。但是,在按鈕定義中,我已將focusableInTouchMode
和focusable
設置爲false。
是否還有其他一些屬性需要定義以允許在這種情況下觸發OnClickListener
事件?
編輯: 多一點調查後,我發現,孩子活動B正在啓動兩次(或更多)和按鈕的每次點擊確實是按預期工作,但看來好像什麼也沒有發生。完整答案吼叫。