How to Identify Buttons
<p>i am developing a Picture Puzzle in android, i have 9 buttons each having its own image except one which is white, now what exactly i want is that when i click any button that is Side by side with the white button or below or above the white white button, the attributes of both the button swaps, i mean the white button changes into the clicked button and the clicked button changes into the white one and also their ids. i am doing this but seems illogical and also not working.</p>

<pre><code>private OnClickListener btnClick = new OnClickListener() {

    public void onClick(View Sender) {

        ImageButton Incoming=(ImageButton) Sender;
        try{    

                ImageButton temp=MyButtons[Incoming.getId()];
                MyButtons[Incoming.getId()].setImageDrawable(MyButtons[Incoming.getId()-1].getDrawable());
                MyButtons[Incoming.getId()].setId(MyButtons[Incoming.getId()-1].getId());
                MyButtons[Incoming.getId()-1].setImageDrawable(temp.getDrawable());
                MyButtons[Incoming.getId()-1].setId(temp.getId());



        }
        catch (Exception e) {
            // TODO: handle exception
            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
        }

    }
};
</code></pre>
