0

I have a source code of an app for android which get location from network or gps. There is the next code:

// Callback method for the "both providers" button.
public void useCoarseFineProviders(View v) {
    mUseFine = false;
    mUseBoth = true;
    setup();
}

There is a button, and on the onClick event call to "useCoarseFineProviders", my question is that I want to delete this button and call this method from the onCreate method, but I don't know how to do this.

I need to learn so much things. Thanks for your help.

Víctor Martín
  • 3,352
  • 7
  • 48
  • 94

1 Answers1

2

Your code isn't actually doing anything, or using the view parameter passed in. so if you want to move it to onCreate, just do it- take the body of the function, paste it into the bottom of onCreate, then delete this function and the code (probably in your xml) telling it to call this function in onClick.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Or he could just pass `null`. – Raghav Sood May 08 '13 at 18:14
  • 1
    You can, but that's ugly and add enough of those and you'll have maintenance issues. From a code cleanliness POV unless you need it to run on clicks as well I wouldn't do that. And then if you did I'd probably refactor it into a helper function that both call, rather than passing null. – Gabe Sechan May 08 '13 at 18:18
  • I totally agree with you there. I'm just suggesting it as a possibility :P – Raghav Sood May 08 '13 at 18:19
  • I had develop in C and C++, and I used to make method to have a sorted code. This is why I'm asking it, I don't know what is the functionality of View. Thanks for your answers. – Víctor Martín May 08 '13 at 22:07