First, the goal
Click on the image on the main screen to enter the corresponding ribbon.
Second, the code implementation.
1. Under the package (Com.example.mobilesafe), The new Class (Settingactivity) inherits activity to implement the functions of the "Set Center", while creating a new layout file under the Layout folder to design the UI of the new class.
2. In the new Class (settingactivity) code, the replication OnCreate method connects the XML layout file and the new Class (settingactivity) through the Setcontentview (int layoutresid) method.
3. Implement the main Page click "Set Center" to enter the new class.
①. In the main page code OnCreate method, set the click events for the GridView object (home_list) through Setonitemclicklistener (Onitemclicklistener listener). And in the parameter new out a Onitemclicklistener, and implements the Onitemclicklistener Onitemclick (adapterview<?> parent, view view, int Position, long id) method. The first parameter in the Onitemclick method adapterview<?> Parent is the GridView object (Home_list), and the second parameter is the view view The view,int position and long ID that you want to click is the location and ID of the view you want to click.
②. In the Onitemclick method, use switch () ... case ... The statement determines which entry is selected based on the location of the click View (position) and then enters the activity (settingactivity) by means of the intent method.
The Setonitemclicklistener method code is as follows:
1Home_list.setonitemclicklistener (NewOnitemclicklistener () {2 3 @Override4 Public voidOnitemclick (adapterview<?>Parent, view view,5 intPositionLongID) {6 Switch(position) {7 Case8:8Intent Intent =NewIntent (homeactivity. This, Settingactivity.class);9 startactivity (Intent); Ten default: One Break; A } - } -});View Code
Android instance-Mobile security Defender (v)-enter the corresponding ribbon from the main interface (set)