当前位置: 首页 > 知识库问答 >
问题:

非抽象且不重写抽象方法

宗政天逸
2023-03-14

大家好,我有这个主课堂

public class Home extends ActionBarActivity
    implements NavigationDrawerFragment.NavigationDrawerCallbacks, FriendsFragment.OnFragmentInteractionListener {

错误:(42,8)错误:Home不是抽象的,并且不会覆盖OnFragmentInteractionListener中的onFragmentInteract(String)抽象方法

我创建了一个导航抽屉,并希望有一个新的片段来显示另一个家庭活动的内容。

Android Studio告诉我做个家。类抽象或实现抽象方法。

里面:

 public interface OnFragmentInteractionListener {
    // TODO: Update argument type and name
    public abstract void onFragmentInteraction(String id);
}

我那样做了,但是什么也没有改变。我不能让home类变得抽象,因为这样它就不能启动应用程序了。

can't instantiate class com.myup2.up2.Home

编辑 1:要调用片段,我认为我正确实现了调用。

 public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransac = fragmentManager.beginTransaction();
    Fragment newFragment = null;
    Bundle args = new Bundle();
    switch(position) {
        case 0:

            break;
        case 1:

            break;
        case 2:
            newFragment = new FriendsFragment();
            break;
    }
    if(newFragment != null) {

        fragmentManager.beginTransaction()
                .replace(R.id.container, newFragment)
                .commit();

    }
}

感谢您的阅读和帮助。

共有1个答案

宁弘亮
2023-03-14

将此添加到您的活动中:

@Override
public void onFragmentInteraction(PUT PARAMETERS HERE IF ANY) {
//do something here, maybe switch to another fragment
}
 类似资料: