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