In general, Button response events inAndroid applications are written in two ways
Button Button=null;
Button.setonclicklistener (New Buttononclicklistener ());
Then write a listener's inner class
Class Buttononclicklistener implements Onclicklistener {
public void OnClick (View v) {
Intent Intent = new Intent ();
Intent.setclass (the current class name . This, jump to the class . Class);
StartActivity (Intent);
}
}
This is the first one, the second of which is as follows
Button.setonclicklistener (New View.onclicklistener () {
public void OnClick (View v) {
Intent Intent = new Intent ();
Intent.setclass (the current class name . This, jump to the class . Class);
StartActivity (Intent);
}
});
When the code check is not wrong, run an error, the following prompt
Many students can not find the reason, the reason is very simple, is to register the corresponding Activity class in the androidmanifest.xml , this kind of covert registration beginner is easy to commit
The specific syntax is <activity name= ". Corresponding class name" ></Activity>
In addition, if you do not specify a good application SDK version, in fact, many of the online simple case source code does not fill out the SDK version. Import into Eclipse The program will explode a lot of red light, the basic error of an R class, in fact, the R class is automatically generated by the system, do not write their own. It 's also easy to set the SDK version
Find androidmanifest.xml, open with mainfest , click Uses Sdk
Min SDK version is the Set app support minimum Android SDK release, 9 for Android 2.3. 8 corresponds to Android2.2, more than 4 of Android can support more than 95%.
Target SDK Versioin is to set your current Android version, Android4.2.2 corresponds to 17,android 4.3 corresponding to 18,android l corresponding 20, set according to the circumstances