Android instance-Mobile security Defender (v)-enter the corresponding ribbon from the main interface (set)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.