Android--intent parameter This problem

Source: Internet
Author: User

Android Intent Parameter This issue(2013-04-02 11:19:48)reproduced
Tags: android Intent Category: Android

Transferred from: http://blog.csdn.net/jiangxinyu/article/details/8572280

The constructor Intent (new XXX. Onclicklistener () {}, Class) is undefined

In Android development, you encounter a situation where the problem occurs when you click a button to enter another activity, and the problem code is as follows:

Onclicklistener () {

public void OnClick (Dialoginterface dialog, int which) {

Intent Intent = new Intent (this, xxxactivity.class);

startactivity (intent);

}

}

This part of the code is in Onclicklistener. The cause of the problem may be that in an anonymous class (the class above is Onclicklistener), this is usually referred to as Onclicklistener instead of activity. The first parameter of intent is the context (it should be noted that activity is not something else (such as the Onclicklistener here)), and therefore the error is caused.

Solution One:

Intent Intent = new Intent (zzzactivity.this, Xxxactivity.class); Solution Two:final Intent Intent = new Intent (zzzactivity.this,xxxactivity.class);***.setonclicklistener (new Onclicklistener) {Public void OnClick (View arg0) {startactivity (intent);    }} Solution Three:final Intent Intent = new Intent (this,xxxactivity.class);***.setonclicklistener (new Onclicklistener) {Public void OnClick (View arg0) {startactivity (intent);    }}

Android--intent parameter This problem

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.