K21*_*213 2 android interface abstract android-fragments navigation-drawer
大家好,我有这个主班
public class Home extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks, FriendsFragment.OnFragmentInteractionListener {
Run Code Online (Sandbox Code Playgroud)
错误:(42,8)错误:Home不是抽象的,并且不会重写OnFragmentInteractionListener中的抽象方法onFragmentInteraction(String)
我创建了一个导航抽屉,并希望有一个新的片段来在Home Activity上显示另一个内容。
Android Studio告诉我使home.class抽象或实现抽象方法。
在这里:
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public abstract void onFragmentInteraction(String id);
}
Run Code Online (Sandbox Code Playgroud)
我做到了,但没有任何改变。而且我无法将home类抽象化,因为那样就无法启动该应用了。
can't instantiate class com.myup2.up2.Home
Run Code Online (Sandbox Code Playgroud)
编辑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();
}
}
Run Code Online (Sandbox Code Playgroud)
感谢您的进阶阅读和帮助。
将此添加到您的活动中:
@Override
public void onFragmentInteraction(PUT PARAMETERS HERE IF ANY) {
//do something here, maybe switch to another fragment
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4894 次 |
| 最近记录: |