0

My Main Activity is AddressFinder, here I start a AddressController:

AddressController ac = new AddressController();

The AddressController should update in some cases:

import android.content.Context;
....
private void updateAddresses() throws IOException {
    Geocoder geocoder = new Geocoder(context);
 for (Address a: address) {
 List<Address> addressIn = geocoder.getFromLocation(a.getLatitude(), 
                                                       a.getLongitude(), 1);
 }
}

Now I have no idea which context I have to use. I don't understand how to use it. I tried this, context, getBaseContext(), getApplicationContext() but nothing worked. Furthermore i tried to give the Adresscontroller an argument with the context (getApplicationContext) of the main activity.

4

2 回答 2

1

我想我有一个解决方案。在主要活动中,我使用以下内容:

ac.updateAddr(getApplicationContext());

在 AddressController 我改变了:

public void updateAddr(Context c) throws IOException {
    updateAddresses(c);
}

这就是我将上下文提供GeocoderAddressController. 工作正常。

于 2010-12-08T20:21:32.117 回答
0

在你的Activity类中创建变量:

Context con = this;  
... 
Geocoder geocoder = new Geocoder(con);

也许使用另一个构造函数?:

public Geocoder (Context context, Locale locale)
于 2010-12-08T18:35:53.637 回答