0

I'm trying to add custom marker in an Async Task class inside onPostExecute method. But when I tried the change marker icon ".icon(BitmapDescriptorFactory.fromResource(R.drawable.)", the image that I coppied to drawable folders is not visible in that method. What could be the problem?

@Override
protected void onPostExecute(JSONObject jobject) {        

    try { 

        // ...

        MarkerOptions bingTrafficMarker = new MarkerOptions()
            .position(positionLatLng)
            .title(strdescription);

        gm.addMarker(bingTrafficMarker); 

        // ...            
    }
}   
Matt Way
  • 32,319
  • 10
  • 79
  • 85
alian
  • 204
  • 1
  • 12

1 Answers1

0

I used an callback method in the onPostExecute to let me get back to my main class.

Here is what I did

Code of the AsyncTask

class AsyncRequest extends AsyncTask<String, Void, Document> {
@Override
protected void onPreExecute() {
}

public interface OnTaskCompleted {

    public abstract void findGeoCode(Document resultCode, String direction);
}

private OnTaskCompleted listener;

public AsyncRequest(OnTaskCompleted listener) {
    this.listener = listener;
}

@Override
protected void onPostExecute(Document result) {
    if (listener != null) {
        listener.findGeoCode(result, direction);
    }
}

Code of the main class that implement the interface callback

private OnTaskCompleted listener = new OnTaskCompleted() {
    @Override
    public void findGeoCode(Document resultCode, String direction) {
        // TODO Auto-generated method stub
        LatLng cord = getLocateAddress(resultCode);
    }

The calling method

new AsyncRequest(listener).execute(paras)

Hope this help

JustWe
  • 633
  • 1
  • 5
  • 18
  • These 2 links are well explained about my solution above http://stackoverflow.com/questions/9963691/android-asynctask-sending-callbacks-to-ui and http://android-er.blogspot.com.au/2013/09/implement-callback-function-with.html – JustWe May 05 '14 at 22:26
  • thanks for your contribution but unfortunately this doesn't help my condition. – alian May 07 '14 at 15:03