Setcontentview switch page (no need to complete findviewbyid every time) -- 2

Source: Internet
Author: User

Http://blog.csdn.net/yanzi1225627/article/details/7802402Here is my previous summary. I want to use it this time. The strange thing is that you can switch from interface a to interface B, from interface B to interface. From A to B again. The final reason is that in the jum2b function, I used the setcontentview (R. layout. B) method instead of the instantiated view bview parameter. Here we will summarize the problem again:

Assume that there are two interfaces, A and B. The button in a is btn1, and the button in B is btn2. it is interface a at startup. then press the buttons btn1 and btn2 to switch to another interface.

1. The two buttons must be global variables. If they are final in the oncreate function, they should also work.

2. Define two view aview = NULL and view bview = NULL in the global variable, and then instantiate it with Inflater in oncreate.

3. Get two functions jump2b and jump2a. The parameters passed by setcontentview in these two functions are defined above.ViewParameters. Both views must be. Then, when findviewbyid is used, call (aview). findviewbyid.

4. Set the listener for btn1 in oncreate, call the jump2b method, instantiate btn2 in the jump2b method, and set the listener. Add a flag. You only need to set the listener once.

 

Note: The main point is that the parameters passed in by setcontentview are the views instantiated by Inflater. They are called (aview). findviewbyid () when the button is instantiated ().

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.