How to update fragment content from activity (viewpager)?

前端 未结 3 629
庸人自扰
庸人自扰 2020-12-08 21:48

I have a simple viewPager with two fragments. Each fragment contains a TextView. I would like to be able to update the text of the current textView displayed from the activi

3条回答
  •  醉梦人生
    2020-12-08 22:27

    @Override
        public int getItemPosition(Object object) {
        XXXFragment fragment = (XXXFragment) object;
            if(…condition){
        fragment.refresh(…);
        }
            return super.getItemPosition(object);
        }
    

    override the above. when you call notifyDataSetChanged(), the above method's triggered. do your refresh as you can.

提交回复
热议问题