0
Examples of a method that requires a View
public void lista(View v) {
Toast.makeText(this, "Ok", Toast.LENGTH_SHORT).show();
}
public void botaoAbrir (View view) {
Intent i = new Intent(this, NovoRegistro.class);
startActivity(i);
}
I’d like to call them inside onCreate()
or any other method that does not require View
.
The way I tried and worked:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lista(new View(this));
}
But the point is, it’s right ?
It can be used like this without problems ? What other ways ?
It’s to my advantage to create a View
to the class, and always call her ?
Understood ramaral ! But this process of separating the 2 methods would be good practice, better performance, security ? Or could call with the "null"
doListaClick(null);
?– rbz
Better performance? Nothing relevant. Best practice? I think so. Pass null as argument usually denotes "gambiarra".
null
is (maybe) the worst error in computer science. The very one Tony Hoare apologizes because of that.– ramaral