如何解决不抽象而不覆盖抽象方法onTabReselected

时间:2015-11-21 12:41:06

标签: java android tabs swipeview

我试图在我的应用中创建navigation drawer。在我的navigation drawer itemView之一中,我希望它有2 tabs具有swipe view功能。我收到错误Viewview is not abstract and does not override abstract method onTabReselected

MainActivity //用于导航抽屉项目

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

private void selectItem(int position) {

        Fragment fragment = null;

        switch (position) {
            case 0:
                fragment=new Information();
                break;
            case 1:

                fragment=new Claims1();
                Bundle bundle=new Bundle();
                bundle.putLong("ab",WorkDetailsTable.ab);
                fragment.setArguments(bundle);
                break;

            case 2:
                fragment=new ViewView();
                break;

            default:
                break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); 

            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(mNavigationDrawerItemTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);

        } else {
            Log.e("MainActivity", "Error in creating fragment");
        }
    }
}

ViewView

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.AdapterView;

public class ViewView extends Fragment implements ActionBar.TabListener {

    private ViewPager viewPager;
    private TabsFragmentPagerAdapter mAdapter;
    private ActionBar actionBar;
    private String[] tabs = {"Information", "receipt"};


    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View View1 = inflater.inflate(R.layout.viewview1, container, false);
        viewPager = (ViewPager) View1.findViewById(R.id.pager);
        mAdapter = new TabsFragmentPagerAdapter(getActivity().getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);
        actionBar = getActivity().getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 0; i < 2; i++) {
            actionBar.addTab(actionBar.newTab().setText(tabs[i]).setTabListener(this));
        }
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg) {
                // TODO Auto-generated method stub
                actionBar.setSelectedNavigationItem(arg);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub

            }


        });


        BuildList();
        return View1;
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getActivity().getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    public void onTabReselected(ActionBar.Tab arg0, FragmentTransaction arg1) {
        // TODO Auto-generated method stub

    }


    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction arg1) {
        // TODO Auto-generated method stub
        viewPager.setCurrentItem(tab.getPosition());
    }


    public void onTabUnselected(ActionBar.Tab arg0, FragmentTransaction arg1) {
        // TODO Auto-generated method stub
    }
}

TabsFragmentPagerAdapter

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class TabsFragmentPagerAdapter extends FragmentPagerAdapter {

    public TabsFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Fragment getItem(int index) {
        // TODO Auto-generated method stub

        switch(index) {
            case 0:
                return new UpdatePage2();
            case 1:
                return new Receipt();

        }
        return null;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 2;
    }

}

错误

  

错误:(50,47)错误:不兼容的类型:android.app.ActionBar不能   转换为android.support.v7.app.ActionBar

1 个答案:

答案 0 :(得分:1)

嗯,错误信息很明确。您的TabListener类实现onTabReselected但不包含onTabReselected的实现。您在实现ViewPager.OnPageChangeListener()的匿名类实例中有onCreateView的实现,您在ViewView方法中定义了该实现。

问题是您需要TabListener来实施TabListener。如果您这样做,请将ViewView所需的方法直接添加到implements ActionBar.TabListener。如果没有,请删除/// <reference path="../modules/ReactSpa/Routing/Router.ts" /> import Router = ReactSpa.Routing.Router; var router = new Router(); router.addParam('id', /([\d\-]+)/); router.add('/articles/:id', 'Article'); console.log(router.find('/articles/1234')); 子句。