4
|
Still being relatively new to this I'm having issues in finding a view in a non-activity class MyLocation which I'm using in my activity class MainActivity. I'm using MyLocation to get longitude and latitude. I want to highlight a textview when either GPS or Network has been used. To do so I need to find the textviews in the non-activity class MyLocation.
Here is how I'm calling it in MainActivity:
And here what I tried in MyLocation to find the textviews:
But the views are not found. I already get a NPE @
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); . What am I doing wrong? | ||
5
|
Because
context is null in MyLocation class. use MyLocation class constructor to pass MainActivity context in MyLocation to access system services as:
and in
MainActivity create MyLocation class object by passing MainActivity context as:
Now use
context to access system services in MyLocation class
EDIT: Instead of inflating main layout again in onLocationChanged use Activity context to access view from Activity Layout as:
|
getLocation
method ? – Spring Breaker Sep 12 '14 at 11:27