gpt4 book ai didi

android - 在选项卡布局 Activity 中,我的 fragment 在滑动时不会刷新

转载 作者:行者123 更新时间:2023-11-30 00:28:03 25 4
gpt4 key购买 nike

我正在使用 fragmentpageradapter 来扩充 fragment ,这是我的编码。我在一个 fragment 中添加购物车项目并将其显示给其他 fragment ,所有 fragment 都采用选项卡布局。我的问题是滑动 fragment 时购物车项目未在其他 fragment 上刷新。

public class ProfileDetailePagerAdapter extends FragmentPagerAdapter 
{
int TabCount;
HashMap<Integer, String> mFragmentTags;
FragmentManager mFragmentManager;
private boolean isPagingEnabled = true;

public ProfileDetailePagerAdapter(FragmentManager fm, int TabCount) {
super(fm);
this.TabCount = TabCount;
mFragmentTags = new HashMap<Integer, String>();
mFragmentManager = fm;
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
MenuFragment tab1 = new MenuFragment();
return tab1;
case 1:
SelectMember_fragment tab2 = new SelectMember_fragment();
return tab2;
case 2:
ViewCart_fragment tab3 = new ViewCart_fragment();
return tab3;
/* case 3:
PaymentMode_fragment tab4=new PaymentMode_fragment();
return tab4;*/
}
return null;
}

@Override
public int getCount() {
return TabCount;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
Object obj = super.instantiateItem(container, position);
if (obj instanceof Fragment) {
// record the fragment tag here.
Fragment f = (Fragment) obj;
String tag = f.getTag();
mFragmentTags.put(position, tag);
}
return obj;
}


public Fragment getFragment(int position) {
String tag = mFragmentTags.get(position);
if (tag == null)
return null;
return mFragmentManager.findFragmentByTag(tag);
}
}

最佳答案

This method is used to add a listener that will be invoked when tab selection changes.

tabLayoutOBJ.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){
public void onTabReselected(TabLayout.Tab tab) {

}
public void onTabSelected(TabLayout.Tab tab){
String getTAB = (String)tab.getText();
// Do your WORK

}
public void onTabUnselected(TabLayout.Tab tab){

}
});

关于android - 在选项卡布局 Activity 中,我的 fragment 在滑动时不会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45004920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com