简单也许愚蠢的问题。我有一个登录活动,它启动另一个活动,这是代码:
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
ActionBar actionBar = getActionBar();
actionBar.hide();
Button btnLogin = (Button) findViewById(R.id.btnLogin);
final TextView tvUsername = (TextView) findViewById(R.id.tvUsername);
final TextView tvPassword = (TextView) findViewById(R.id.tvPassword);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (tvUsername.getText().toString().length()<1) {
Toast msg = Toast.makeText(LoginActivity.this, "Enter a Username", Toast.LENGTH_LONG);
msg.setGravity(Gravity.TOP|Gravity.LEFT, 0, 70);
msg.show();
tvUsername.requestFocus();
} else if (tvPassword.getText().toString().length()<1) {
Toast msg = Toast.makeText(LoginActivity.this, "Enter a Password", Toast.LENGTH_LONG);
msg.setGravity(Gravity.TOP|Gravity.LEFT, 0, 200);
msg.show();
tvPassword.requestFocus();
} else {
startActivity(new Intent(LoginActivity.this,CrewScheduleActivity.class));
finish();
}
}
});
}
}
我的问题是关于文本视图。Eclipse 基本上说我必须使它们最终化才能在按钮的 onClick 事件中使用它们。NP所以我这样做了,它奏效了。
问题是将这些放在@Override 之上作为私有与在 OnCreate 中作为最终有什么区别?