2

I try to trigger swipeRefreshLayout indicator when my app run but it's not triggered! I have listView with my custom Adapter, I load JSON from an URL and set it in my listView, I want to show loading indicator at first run. I try these ways: 1.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View rootView = inflater.inflate(R.layout.fragment_main, container, false);
   swipeContainer = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
   swipeContainer.setOnRefreshListener(this);
   //it's not working!
   swipeContainer.setRefreshing(true);
   return rootView;
}

2.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
   // It's not working!!
   swipeContainer.setRefreshing(true);
}

Note: I'm sure my SwipeRefreshLayout is fine because on onStart or onRefresh method worked currently.

Any solution appreciated :)

Reza
  • 73
  • 9

1 Answers1

2

try with a Runnable Method in your onCreateView

swipeContainer.post(new Runnable() {
@Override
public void run() {
    swipeContainer.setRefreshing(true);
}
});
Mounir Elfassi
  • 2,242
  • 3
  • 23
  • 38