如何实现OnFragmentInteractionListener
Myapp E/AndroidRuntime:致命异常:main java.lang.ClassCastException:com.domain.myapp.MainActivity@422fb8f0必须实现OnFragmentInteractionListener
import 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();
}
相关分类