0
Which of the most recommended strategies for a good application performance? Using findViewById
whenever we use some element of View
or to do so 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);
}
}
I particularly if I will use in various situations and again and again I prefer to create a variable, to avoid processing and reduce memory allocation, instantiated at once rather than instantiating about 500 times
– GabrielLocalhost