Reputation: 161
So I have two files (MainActivity.java
and HomeFragment.java
) and I am trying to pass a public static void
called displayPromptForEnablingGPS
from HomeFragment
to MainActivity
. Here is the code
HomeFragment.java
(the code I'm trying to pass)
public static void displayPromptForEnablingGPS(
final Activity activity)
{
final AlertDialog.Builder builder =
new AlertDialog.Builder(activity);
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
final String message = "Enable either GPS or any other location"
+ " service to find current location. Click OK to go to"
+ " location services settings to let you do so.";
builder.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
activity.startActivity(new Intent(action));
d.dismiss();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
d.cancel();
}
});
builder.create().show();
}
MainActivity.java
(how I'm trying to call it)
public void showMainView() {
HomeFragment.displayPromptForEnablingGPS();
}
But I get an error saying
"HomeFragment.displayPromptForEnablingGPS();" is invalid
Upvotes: 0
Views: 68
Reputation: 2202
The method you want to call requires a parameter but you don't pass it.
public static void displayPromptForEnablingGPS(
final Activity activity)
Your method in MainActivity should look like this:
public void showMainView() {
HomeFragment.displayPromptForEnablingGPS(this);
}
Upvotes: 1