如何实现OnFragmentInteractionListener我在Androidstudio 0.8.2中有一个带有导航抽屉的向导生成的应用程序我创建了一个片段并将其添加到newInstance()中,得到了以下错误:Myapp E/AndroidRuntime:致命异常:main java.lang.ClassCastException:com.domain.myapp.MainActivity@422fb8f0必须实现OnFragmentInteractionListener我找不到如何实现这个OnFragmentInteractionListener?即使在AndroidSDK文档中也找不到它!MainActivity.javaimport android.app.Activity;import android.app.ActionBar;import android.app.Fragment;import android.app.FragmentManager;import android.os.Bundle;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.support.v4.widget.DrawerLayout;public class MainActivity extends Activity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/private NavigationDrawerFragment mNavigationDrawerFragment;/**
* Used to store the last screen title. For use in {@link #restoreActionBar()}.
*/private CharSequence mTitle;@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));}@Overridepublic void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();}
3 回答
- 3 回答
- 0 关注
- 869 浏览
添加回答
举报
0/150
提交
取消