Which of the following strategies is best suited for good application performance? Use findViewById
whenever we use any element of View
or do it only once by assigning to a variable?
example in Xamarin.Android
:
public class MainActivity : Activity
{
private EditText _CampoNome;
protected override void OnCreate(Bundle savedInstanceState)
{
...
_CampoNome = FindViewById<EditText>(Resource.Id.edtCampoNome);
_CampoNome.Text = "ola mundo";
EscreverNome();
}
private void EscreverNome()
{
Console.WriteLine(_CampoNome.Text);
}
}
or
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
...
FindViewById<EditText>(Resource.Id.edtCampoNome).Text = "ola mundo";
EscreverNome();
}
private void EscreverNome()
{
Console.WriteLine(FindViewById<EditText>(Resource.Id.edtCampoNome).Text);
}
}