Still relatively new to this, I am having trouble finding a view in the inactive MyLocation class that I use in my MainActivity activity class. I use MyLocation to get longitude and latitude. I want to highlight text when using GPS or network. To do this, I need to find text views in the MyLocation inactivity class.
This is what I call it in MainActivity:
public class MainActivity extends ActionBarActivity implements LocationListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MyLocation myLocation = new MyLocation(); myLocation.getLocation(this, locationResult); }
And here is what I tried to find in MyLocation in the text:
public class MyLocation { LocationManager lm; LocationResult locationResult; private Context context; TextView tvnetwork, tvgps; private int defaultTextColor; LocationListener locationListenerNetwork = new LocationListener() { public void onLocationChanged(Location location) { locationResult.gotLocation(location); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.main, null); tvnetwork = (TextView) v.findViewById(R.id.tvnetwork); tvgps = (TextView) v.findViewById(R.id.tvgps); defaultTextColor = tvgps.getTextColors().getDefaultColor(); tvnetwork.setTextColor(context.getResources().getColor( R.color.green)); tvgps.setTextColor(defaultTextColor); lm.removeUpdates(this); lm.removeUpdates(locationListenerGps); } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } };
But no views were found. I already got NPE @ .getSystemService(Context.LAYOUT_INFLATER_SERVICE); . What am I doing wrong?
android layout-inflater
sascha
source share