Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Final vs Private textviews
    primarykey
    data
    text
    <p>simple maybe stupid question. I have a login activity which launches another activity, and here's the code:</p> <pre><code>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()&lt;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()&lt;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(); } } }); } } </code></pre> <p>My question is about the textviews. Eclipse basically said i had to make them final in order to use them in the onClick event of the button. NP so i did that and it worked.</p> <p>The question is What is the difference between putting these above the @Override as private vs inside the OnCreate as final?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload