johnkil / Android-ProgressFragment

Implementation of the fragment with the ability to display indeterminate progress indicator when you are waiting for the initial data.
http://johnkil.github.io/Android-ProgressFragment/
Apache License 2.0
807 stars 214 forks source link

Tons of ProgressFragment.ensureContent errors #25

Open Swisyn opened 9 years ago

Swisyn commented 9 years ago

Sometimes i get tons of error feedbacks from my users about the lib.

java.lang.IllegalStateException: Content view not yet created at com.devspark.progressfragment.ProgressFragment.ensureContent(ProgressFragment.java:273) at com.devspark.progressfragment.ProgressFragment.setContentEmpty(ProgressFragment.java:250)

My fragments like; public class BusListFragment extends ProgressFragment { private Context context; private CardRecyclerView cardRecyclerView; private View rootView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    setRetainInstance(true);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_mycards, container, false);
    context = getActivity();
    cardRecyclerView = (CardRecyclerView) rootView.findViewById(R.id.cardRecyclerView);
    return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setContentView(rootView);
    if (stopId != null && location != null) {
        new getClosestBusListAsync(this).execute();
    }
}

} and the task is like; public class getClosestStopListAsync extends AsyncTask<Void, Void, String> { ProgressFragment fragment; Context context; GoogleMap map; LatLng location;

public getClosestStopListAsync(ProgressFragment fragment, LatLng location, GoogleMap map) {
    this.fragment = fragment;
    this.context = fragment.getActivity();
    this.location = location;
    this.map = map;
}

@Override
protected String doInBackground(Void... args0) {
    return new RequestHelper().getClosestStopList(PreferenceHelper.getCity(context), location.latitude, location.longitude);
}

@Override
protected void onPostExecute(String result) {
    super.onPostExecute(result);
    if (result != null) {
        map.clear();

        BusStop stopList = JsonHelper.getClosestStopList(result);
        if (stopList != null) {
            if (stopList.getResult().getCode().equals("0")) {
                if (stopList != null || stopList.getBusStopList().size() > 0) {
                    for (BusStop.BusStopItem busStop : stopList.getBusStopList()) {
                        map.addMarker(new MarkerOptions()
                                .position(new LatLng(Double.parseDouble(busStop.getLatitude()), Double.parseDouble(busStop.getLongitude())))
                                .title(busStop.getStopId() + " - " + busStop.getStopName() + " - " + busStop.getType())
                                .snippet(busStop.getRoutes())
                                .icon(BitmapDescriptorFactory.fromResource(R.drawable.stop)));
                    }
                    fragment.setContentEmpty(false);
                } else {
                    fragment.setContentEmpty(true);
                    fragment.setEmptyText(R.string.empty_list);
                }
            }
        }
        System.gc();
        fragment.setContentShown(true);
    }
}

}

how can it be possible that content view not yet created? OnActivityCreated is called after OnCreateView so that means views could be created?

How can i fix this issue? Thanks.

mitsus commented 9 years ago

HI Swisyn, i've the same problem. You were able to find a solution?

Thanks a lot

Swisyn commented 9 years ago

this is so useless library and i gave up to using it. I use progresslayout lib or multistateview lib. @mitsus

casperbang commented 8 years ago

We also have lots of issues with ensureContent errors, often associated with calls to setContentShown(false).