You do not need to configure the click listener manually in the code. The easiest way to do this is to add a callback to XML.
Like this:
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignRight="@+id/button7" android:onClick="foo" android:text="Edit" />
If you use eclipse with android tools, you can set this property directly in the XML editor. Then you define the function in your code, named after the Click property, and it will be called automatically.
public void foo(View oView) { Button cklicked ... }
You can also set up a dynamic click, but you only need it if you create buttons on the fly, like this:
ImageButton button = (ImageButton) findViewById(R.id.list_manager_add); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { button pressed... } });
source share