Reputation: 3038
I'm having trouble in initializing my controls in Android. In my app, I will have buttons that will be available or will be used in different activities and all do the same function which is to navigate to another activity. I want to declare my controls publicly so that I wont declare them repetitively on my classes. Say like I want to do the code below into a separate class of its own and then just call the function when I need to initialize my controls.
InitControls():
TextView text1;
Button button1;
text1 = (TextView)FindViewById(R.id.TextView1);
button1 = (Button)FindViewById(R.id.Button1);
text1.setText("Hello WOrld!");
How do I put that code into a function and then just call it in my activity like this?
InitControls(); //or something
Upvotes: 1
Views: 1562
Reputation: 5535
Put the InitControls call in a Base class that inherits from Activity then in your activities extend this class and call InitControls in the onCreate?
Upvotes: 3