views:

143

answers:

2

Hi,

I created a layout with two buttons: btnMode and btnAction.

There are clickListeners set for each:

btnMode.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                onModeButton();
            }
        });

        btnAction.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                onActionButton();
                updateGUIState();

            }
        });

But when I test the buttons in both cases (when btnAction and btnMode are clicked) the listener, which is set for btnAction executes so I guess both graphich elements on the screen are set as btnAction.

I tried to find any possible error in .xml file but havent found any. So just for testing I tried to bind graphic elements the opposite way:

Original:

        btnMode = (ImageButton)findViewById(R.id.btnCaptureMode);
        btnAction = (ImageButton) findViewById(R.id.btnACtion);

Opposite:

        btnAction = (ImageButton)findViewById(R.id.btnCaptureMode);
        btnMode = (ImageButton) findViewById(R.id.btnACtion);

In this case both clickListeners were executed but of course the button roles were switched.

I have been looking for possible cause two days now and still haven't figured out where the issue is.

The part of .xml file which affects buttons is the following:

<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content"
             android:id="@+id/btnCaptureMode"
             android:src="@drawable/button_capture_mode" android:background="@drawable/transparent_background" />
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnACtion"
             android:src="@drawable/button_action"
             android:background="@drawable/transparent_background" />

Has anyone of you experienced similar problem or knows where to look for an error?

Thanks!

A: 

Check your layout xml may be you messed with id's? May be you can show it here BTW.

Nikolay Ivanov
A: 

Is it possible that your onModeButton(), onActionButton(), or updateGUIState() methods are invoking each other or doing anything unusual?

Mike