[Android] news client realizes left navigation and click switching
Set the main layout file and set an ID for the root layout as the content area
Set the click event for the listview entry, setonitemclicklistener() method, parameter: Context
The current fragment implements the onitemclicklistener interface
Implement the onitemclick() method
Switch judges the index position of the current menu and instantiates different fragment objects according to the index
Call getactivity () method to get the host activity object. This activity exposes a method to replace the fragment
Use the keyword instances of to judge that getactivity() gets an instance of mainactivity class
Call the switchmenufragment() method of the host activity object to switch the fragment of the content part. Parameter: fragment object
Host activity exposure method switchmenufragment(), switch content area fragment, parameter: fragment object
getSupportFragmentManager().beginTransaction().replace(R.id.ll_main_content,fragment).commit();
Call the toggle () method of the slidingmenu object to close the left menu
Set the default to display the contents of the first navigation when the app is opened for the first time
MainActivity
MenuFragment.java