I have a custom Android (1.5) Title bar which includes a button. Using the custom title bar in Activity A, I am able to click the button, and have the OnClickListener
event fire as expected.
However, when I launch Activity B for result, from Activity A, it can take 2-3 clicks for the same buttons event to fire.
This is the code to set the event listener for Activity A in the onCreate
override
setTitleNegativeActionListener(new OnClickListener() {
public void onClick(View v) { // end this activity ActivityA.this.finish(); } });
This is the code for Activity B
setTitleNegativeActionListener(new OnClickListener() {
public void onClick(View v) { setResult(RESULT_CANCELED); EditClientAddressActivity.this.finish(); } });
Button XML from layout
<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" />
It seems as though in Activity B, the first click is putting the button into focus, and the second click is actually pressing the button. However, I have set both focusableInTouchMode
and focusable
to be false in the buttons definition.
Is there some other property that needs to be defined to allow the OnClickListener
event to fire in this case?
EDIT: After a bit more investigation I found that the child Activity B was being started twice (or more) and each click of the button was indeed working as expected, but appeared as though nothing was happening. Full answer bellow.