The method setonclicklistener (view. onclicklistener) in the type view is not applicable

Source: Internet
Author: User

Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. widget. Button;
Import Android. content. dialoginterface;
Import Android. content. dialoginterface. onclicklistener;
Import Android. content. intent;
Import Android. View. view;

Public class activity_01activity extends activity {

/** Called when the activity is first created .*/
Private button mybutton = NULL;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Mybutton = (button) findviewbyid (R. Id. mybutton );
Mybutton. settext ("second activity ");
Mybutton. setonclicklistener (New mybuttonlistener ());

}

/*

Class mybuttonlistener implements onclicklistener {
@ Override
Public void onclick (dialoginterface dialog, int which) {// when you move the cursor over mybuttonlistener, a prompt is displayed. Click Add. This is the default function.
// Todo auto-generated method stub
Intent intent = new intent ();
Intent. setclass (activity_01activity.this, otheractivity. Class );
Activity_01activity.this.startactivity (intent );
}
}

*/

Class mybuttonlistener implements Android. View. View. onclicklistener {
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Intent intent = new intent ();
Intent. setclass (activity_01activity.this, otheractivity. Class );
Activity_01activity.this.startactivity (intent );
}
}

}

/***/The comment Part replaces the following class mybuttonlistener implements Android. View. View. onclicklistener,

The following error occurs: mybutton. setonclicklistener (New mybuttonlistener ());

In the sentence, setonclicklistener is displayed in the red line. When you move the cursor over it, the following message is displayed:

The method setonclicklistener (view. onclicklistener) in the type view is not applicable for the arguments (activity_01activity.mybuttonlistener)

If it is written above, comment out the error description and run it without errors.

PS is just getting started. If someone else doesn't see the answer they want, just give it a try. Haha

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.