我尝试在我的应用运行时触发swipeRefreshLayout指示器,但它没有被触发!我有自定义适配器的listView,我从URL加载JSON并在我的listView中设置它,我想在第一次运行时显示加载指示器。 我尝试这些方法: 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);
}
注意:我确定我的SwipeRefreshLayout很好,因为onStart或onRefresh方法当前工作。
任何解决方案都赞赏:)
答案 0 :(得分:2)
尝试使用Runnable
onCreateView
方法
swipeContainer.post(new Runnable() {
@Override
public void run() {
swipeContainer.setRefreshing(true);
}
});