I would like to set my variables at the top of my class instead of in the
method
I can't seem to tackle this confusing problem, I have lots and lots of
things that I would like to add at the top of my class to help cut down on
clutter.
Since multiple methods use these checkbox variables.
I would like to have everything at the top directly under the opening
bracket.
Here's what works, but not what I want.:
public class MyClass extends Activity implements View.OnClickListener {
//leaving out most code like onCreate. Just pretend it's there.
public void checkboth(View view) {
CheckBox cb1 = (CheckBox) findViewById(R.id.cb1);
CheckBox cb2 = (CheckBox) findViewById(R.id.cb2);
cb1.setchecked(true);
cb2.setchecked(true);
}
@Override
public void onClick(View v) {
}
}
But for the life of me I can't figure out why I can't do this:
public class MyClass extends Activity implements View.OnClickListener {
CheckBox cb1 = (CheckBox) findViewById(R.id.cb1);
CheckBox cb2 = (CheckBox) findViewById(R.id.cb2);
//leaving out most code like onCreate. Just pretend it's there.
public void checkboth(View view) {
cb1.setchecked(true);
cb2.setchecked(true);
}
@Override
public void onClick(View v) {
}
}
No comments:
Post a Comment