I'm trying to make Android onClick()
method easier to read, so I wrap it like this
public void click(Button bt) {
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {}
});
}
When I try to run it like this
button = (Button) findViewById(R.id.btn1);
click(button) {
@Override
public void onClick(View v) {
Log.v("hi", "test");
}
}
or
button = (Button) findViewById(R.id.btn1);
click(button) {
@Override
public void onClick(View v) {
Log.v("hi", "test");
}
};
or
button = (Button) findViewById(R.id.btn1);
click(button) {
@Override
public void onClick(View v) {
Log.v("hi", "test");
};
};
it gives the following errors:
[error] /home/retok/proj/src/com/hellow/app/HelloActivity.java:32: ';' expected
[error] /home/retok/proj/src/com/hellow/app/HelloActivity.java:34: ';' expected
[error] /home/retok/proj/src/com/hellow/app/HelloActivity.java:34: ';' expected
[error] (compile:compileIncremental) javac returned nonzero exit code
Why is this? As you can see I put ;
where needed. And I can't put ;
after public void onClick(View v) {
and click(button) {
because that would close the method and give error anyway.