I am trying to create a test application that when I press an ImageButton, a log message appears. Simple.
I want the ImageButton view to work with a class.
I have done this as so: UPDATED WITH CORRECT NAME OF CONSTRUCTOR
public class MainActivity extends Activity {
  MyButtonClass btnOk = null;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        btnOk = new ButtonClass(this);      
        setContentView(R.layout.activity_main);
  }
}
class MyButtonClass extends ImageButton{
        public MyButtonClass(Context context) {
            super(context);
            findViewById(R.id.btButton);
              OnClickListener oclBtnOk = new OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    // change text of the TextView (tvOut)
                   Log.e("Log This:","Yay! I am working!");
                  }
                };
                setOnClickListener(oclBtnOk);
        }
    }
My layout xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageButton
        android:id="@+id/btButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>
When I run the app, I don't get any erros on Log cat and the application does not quit however the ImageButton does not do anything when I press it :/
 
     
     
     
    