我是Android新手所以请详细解释
我想构建一个使用Tabs的基本Android应用。 我已经构建了一个TabListener。
但它给我一个错误。我该如何解决?
以下是代码:
package com.adhish.tabs1;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.support.v7.app.ActionBar.TabListener;
import android.support.v7.app.ActionBar.Tab;
import android.widget.Toast;
@SuppressLint("NewApi")
public class MyTabsListener implements TabListener {
public Fragment fragment;
//Create fragment for Activity
public MyTabsListener(Fragment fragment)
{
this.fragment = fragment;
}
public void onTabReselected(Tab tab, FragmentTransaction transaction)
{
Toast.makeText(ActionBarImpl.myContext, "You have clicked again !", Toast.LENGTH_SHORT).show();
}
public void onTabSelected(Tab tab, FragmentTransaction transaction)
{
transaction.replace(R.id.actionbar, fragment);
}
public void onTabUnselected(Tab tab, FragmentTransaction transaction)
{
transaction.remove(fragment);
}
}
错误发生在此类的声明中:
Class MyTabsListener must be declared either Abstract or implement Abstract method
'onTabSelected(Tab, FragmentTransaction)' in 'TabListener'.
请帮我解决这个问题。