大家好,我有这个Main Class Home
public class Home extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks, FriendsFragment.OnFragmentInteractionListener {
错误:(42,8)错误:Home不是抽象的,并且不会覆盖OnFragmentInteractionListener中的抽象方法onFragmentInteraction(String)
我创建了一个导航抽屉,并想要一个新的片段来显示另一个内容然后在家庭活动上。
Android Studio告诉我要创建home.class抽象或实现抽象方法。
在这里:
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public abstract void onFragmentInteraction(String id);
}
我做到了但没有改变。我不能让家庭课抽象,因为它不再启动应用程序了。
can't instantiate class com.myup2.up2.Home
编辑1: 要调用Fragment我认为我正确地实现了调用。
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();
}
}
感谢先进和帮助阅读。
答案 0 :(得分:5)
将此添加到您的活动中:
@Override
public void onFragmentInteraction(PUT PARAMETERS HERE IF ANY) {
//do something here, maybe switch to another fragment
}