1

プロジェクトへの v7 サポート ライブラリの追加が完了したところですが、次のエラーが発生します。

Description Resource    Path    Location    Type
The method setTabListener(ActionBar.TabListener) in the type ActionBar.Tab is not applicable for the arguments (ActionBar.TabListener)  TabsViewPagerFragmentActivity.java  /LoginAndRegistration/src/com/example/loginandregistration  line 76 Java Problem
 The method setTabListener(ActionBar.TabListener) in the type ActionBar.Tab is not applicable for the arguments (ActionBar.TabListener) TabsViewPagerFragmentActivity.java  /LoginAndRegistration/src/com/example/loginandregistration  line 80 Java Problem
The type new ActionBar.TabListener(){} must implement the inherited abstract method ActionBar.TabListener.onTabUnselected(ActionBar.Tab, FragmentTransaction)   TabsViewPagerFragmentActivity.java  /LoginAndRegistration/src/com/example/loginandregistration  line 52 Java Problem
The type new ActionBar.TabListener(){} must implement the inherited abstract method ActionBar.TabListener.onTabReselected(ActionBar.Tab, FragmentTransaction)   TabsViewPagerFragmentActivity.java  /LoginAndRegistration/src/com/example/loginandregistration  line 52 Java Problem
The type new ActionBar.TabListener(){} must implement the inherited abstract method ActionBar.TabListener.onTabSelected(ActionBar.Tab, FragmentTransaction) TabsViewPagerFragmentActivity.java  /LoginAndRegistration/src/com/example/loginandregistration  line 52 Java Problem
The method setTabListener(ActionBar.TabListener) in the type ActionBar.Tab is not applicable for the arguments (ActionBar.TabListener)  TabsViewPagerFragmentActivity.java  /LoginAndRegistration/src/com/example/loginandregistration  line 72 Java Problem

ここに私の TabsViewPagerFragmentActivity.java があります:

package com.example.loginandregistration;

import android.app.ActionBar.Tab;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.LocalBroadcastManager;
import com.example.loginandregistration.MyPageAdapter;
import android.support.v7.app.ActionBar;

class TabsViewPagerFragmentActivity extends FragmentActivity {

// Declare Variables
android.app.ActionBar ActionBar;
ViewPager mPager;
Tab tab;

  @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from dashboard.xml
    setContentView(R.layout.dashboard);

    // Activate Navigation Mode Tabs
    ActionBar = getActionBar();
    ActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Locate ViewPager in dashboard.xml
    mPager = (ViewPager) findViewById(R.id.pager);

    // Capture ViewPager page swipes
    ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            // Find the ViewPager Position
            ActionBar.setSelectedNavigationItem(position);
        } 
    };

    mPager.setOnPageChangeListener(ViewPagerListener);
    // Locate the adapter class called ViewPagerAdapter.java
    MyPageAdapter viewpageradapter = new MyPageAdapter(getSupportFragmentManager());
    // Set the View Pager Adapter into ViewPager
    mPager.setAdapter(viewpageradapter);

    // Capture tab button clicks
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {

         public void onTabSelected(Tab tab, FragmentTransaction ft) {
             // Pass the position on tab click to ViewPager
             mPager.setCurrentItem(tab.getPosition());
         }

         public void onTabUnselected(Tab tab, FragmentTransaction ft) {
             // TODO Auto-generated method stub
         }

         public void onTabReselected(Tab tab, FragmentTransaction ft) {
             // TODO Auto-generated method stub
         }

     };



    // Create first Tab
    tab = ActionBar.newTab().setText("Tab1").setTabListener(tabListener);
    ActionBar.addTab(tab);

    // Create second Tab
    tab = ActionBar.newTab().setText("Tab2").setTabListener(tabListener);
    ActionBar.addTab(tab);

    // Create third Tab
    tab = ActionBar.newTab().setText("Tab3").setTabListener(tabListener);
    ActionBar.addTab(tab);

}

}

setTabListener エラーを修正する方法はわかりませんが、エラーについては次のとおりです。

The type new ActionBar.TabListener() ect.

実装されていないメソッドを追加すると、それらが onTabSelected、onTabUnselected、onTabReselected メソッドと同じメソッドであることがわかります。

どうすればこれを修正できますか?

4

2 に答える 2

2

インポートを置き換える

import android.app.ActionBar.Tab;
import android.app.FragmentManager;
import android.app.FragmentTransaction;

import android.support.v7.app.ActionBar.Tab;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

サポート ライブラリ用の別のセット オフ クラスがあります。

編集

交換する必要もあります

android.app.ActionBar ActionBar;

ActionBar ActionBar;

サポート ライブラリのアクション バーを使用します。actionBarまた、変数名を小文字にして、クラス名と区別した方がよいかもしれません。

于 2013-09-28T23:09:13.770 に答える
0

ActionBar.TabListener を実装していることを確認してください。this は、フラグメント/アクティビティ自体ではなく、その実装を参照しています。

于 2015-03-30T13:50:01.560 に答える