我使用一個名爲SwipeRefreshLayout的小部件,當有人推送視圖時刷新我的片段。如何重新創建一個片段?
要重新創建活動我必須使用:
SwipeRefreshLayout mSwipeRefreshLayout;
public static LobbyFragment newInstance() {
return new LobbyFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_lobby, container, false);
receiver = new MySQLReceiver();
rlLoading = (RelativeLayout) view.findViewById(R.id.rlLoading);
gvLobby = (GridView) view.findViewById(R.id.gvLobby);
updateList();
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.mSwipeRefreshLayout);
mSwipeRefreshLayout.setColorSchemeResources(R.color.pDarkGreen, R.color.pDarskSlowGreen, R.color.pLightGreen, R.color.pFullLightGreen);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
getActivity().recreate();
}
});
return view;
}
但我不希望重新創建包含該視圖尋呼機充分的活動,我想重新片段。我怎樣才能做到這一點?
分享你的片段創建代碼 – Nikhil
是因爲你想更新你的數據列表裏面的片段? –
是的,我正在使用gridview,我想更新該gridview –