activity 开始或创建时如何触发 swipeRefreshLayout 指示器
How trigger swipeRefreshLayout indicator when activity started or created
我尝试在我的应用 运行 时触发 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 方法当前有效。
感谢任何解决方案:)
尝试在 onCreateView
中使用 Runnable
方法
swipeContainer.post(new Runnable() {
@Override
public void run() {
swipeContainer.setRefreshing(true);
}
});
我尝试在我的应用 运行 时触发 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 方法当前有效。
感谢任何解决方案:)
尝试在 onCreateView
Runnable
方法
swipeContainer.post(new Runnable() {
@Override
public void run() {
swipeContainer.setRefreshing(true);
}
});