[英]TabMain is not abstract and does not override abstract method onTabReselected(Tab,FragmentTransaction) in TabListener
Good day guys. 大家好 I'm trying to build a simple app which support tab layout with a swipe view feature.
我正在尝试构建一个支持滑动视图功能的选项卡布局的简单应用程序。 I follow this tutorial but no success.
我遵循本教程,但没有成功。
package com.example.project.project;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.app.ActionBar;
import android.view.Menu;
public class TabMain extends FragmentActivity implements ActionBar.TabListener{
private ViewPager viewPager;
private ActionBar actionBar;
private TabsFragmentPagerAdapter tabsAdapter;
private String[] days = new String[]{"Information","Claim"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_main);
viewPager = (ViewPager) findViewById(R.id.viewPager);
tabsAdapter = new TabsFragmentPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(tabsAdapter);
actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for(int i=0; i<2; i++){
actionBar.addTab(actionBar.newTab().setText(days[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
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
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
}
}
I have follow each single step from the tutorial, but I get error as below. 我已按照本教程中的每个步骤进行操作,但出现以下错误。
Error:(13, 8) error: TabMain is not abstract and does not override abstract method onTabReselected(Tab,FragmentTransaction) in TabListener
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
And I get a red line underneath this statement public class TabMain extends FragmentActivity implements ActionBar.TabListener{
我在此语句下得到一条红线。
public class TabMain extends FragmentActivity implements ActionBar.TabListener{
You're using the wrong FragmentTransaction
class for that interface, which uses android.app.FragmentTransaction
, not android.support.v4.app.FragmentTransaction
. 您为此接口使用了错误的
FragmentTransaction
类,该类使用android.app.FragmentTransaction
,而不是android.support.v4.app.FragmentTransaction
。 Since the your method signature doesn't match the interface's, you're not actually implementing the correct method. 由于您的方法签名与接口的签名不匹配,因此您实际上并未实现正确的方法。 The old
ActionBar
and it's related classes don't work with those support classes. 旧的
ActionBar
及其相关类不适用于这些支持类。
ActionBar.TabListener
docs ActionBar.TabListener
文档
Please note that that class had been deprecated, and Google recommends that you change how you handle navigation within your app. 请注意,该类已被弃用,Google建议您更改在应用内处理导航的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.