onbackpressed() 时如何刷新片段中的列表视图 [英] How to refresh listview in fragment when onbackpressed()

查看:26
本文介绍了onbackpressed() 时如何刷新片段中的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在按下时刷新 listview fragmentA

I want to refresh listview fragmentA when back pressed

示例:

我在 FragmentA 到 FragmentB 的列表视图中单击 onitem

I click onitem in listview in FragmentA to FragmentB

当我在 FragmentB 中单击返回(在 Activity 中)时,我想刷新列表视图片段A.

and when I click back (in Activity) in FragmentB ,I want to refresh listview FragmentA.

对不起,我的英语不好.

sorry My english is not good.

如何在 FragmentA 中设置 onViewCreated OR onResume ???

How to set onViewCreated OR onResume in FragmentA ???

和我的活动

@Override
    public void onBackPressed() {
        super.onBackPressed();

我的片段A

 @Override
    public void setItems(ArrayList<NotificationListModel> items,String last_page) {
        Log.d("NotificationFragment", "setItems ");
        this.notificationListModels=items;
        this.last_page=last_page;

        for (NotificationListModel notificationListModel: notificationListModels){
            notificationListModelArrayList.add(notificationListModel);
        }
        getData();
        if (getActivity()!=null) {
            int currentPosition = getListView().getFirstVisiblePosition();
            adapNotificationList = new AdapNotificationList(getActivity(), notificationListModelArrayList);
            setListAdapter(adapNotificationList);
            adapNotificationList.notifyDataSetChanged();
            getListView().setSelection(currentShowList);
            getListView().setSelectionFromTop(currentPosition + 1, 0);
        }
    }

推荐答案

覆盖 Fragment A 中的 onResume 并调用 adapter.notifyDataSetChanged() 或处理列表视图数据刷新的函数.

Override onResume in Fragment A and call adapter.notifyDataSetChanged() or the function which is handling data refresh of your listview.

@Override
public void onResume() {
    super.onResume();
    adapter.notifyDataSetChanged();
    //OR
    callDataRefreshFunction();

}

您不需要在 Activity 中处理 onBackPressed.

You do not need to handle onBackPressed in Activity.

这篇关于onbackpressed() 时如何刷新片段中的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆