I have created a button in my Android application & I tried to set onclick listner to run onClick method like follows
...
Button btn_ok;
btn_ok = (Button)findViewById(R.id.button1);
btn_ok.setOnClickListener(this);
}
public void onClick() {
EditText uN = (EditText) findViewById(R.id.EditText04);
uN.setText("Clicked!");
}
But Eclipse shows an error & says that “setOnClickListener” need to Cast Argument. After casting it is like this
btn_ok.setOnClickListener((OnClickListener) this);
Then when I’m running the program Emulator says that “Program has stopped unexpectedly”…
How can I solve this problem ?
Make sure that your class implements View.OnClickListener. You can`t just add onClick method, you must implement interface