在刷卡选项卡上刷新android

时间:2015-06-10 15:16:18

标签: android android-fragments android-viewpager

我正在使用视图寻呼机和片段。我有三个可跳转的标签。每个扩展片段。我希望他们刷卡时刷新它们。怎么做到这一点?现在,当我滑动时,标签不会刷新。

public class Orders extends FragmentActivity implements
    ActionBar.TabListener {

private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "Pending", "Completed", "Rejected" };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_orders);
    this.setTitle((Html.fromHtml("<font color=\"#ffffff\">" + "pharmeazy-mobile" + "</font>")));
    // Initilization
    viewPager = (ViewPager)findViewById(R.id.pager1);
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
    actionBar=getActionBar();
    getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#69acdf")));
    viewPager.setAdapter(mAdapter);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        

    // Adding Tabs
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name)
                .setTabListener(this));
    }

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // on tab selected
    // show respected fragment view
    viewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}

请帮忙

1 个答案:

答案 0 :(得分:0)

不要使用 ActionBar 。看看TabLayout这是Google在上一次支持更新中发布的带有标签的ViewPager的新布局。 它将解决您的问题