During this time, I watched Android and saw the anonymous internal classes in Java. In my opinion,. Net does not support anonymous internal classes.
Anonymous classes cannot be referenced because they cannot have names. They must be declared as part of the new statement at creation. This requires another new statement, as shown below:
New <class or interface> <class subject>
This new statement declares a new anonymous class, which extends a given class or implements a given interface. It also creates a new instance of that class and returns it as the result of the statement. The class to be extended and the interface to be implemented are the operands of the new statement, followed by the subject of the anonymous class. If an anonymous class is extended to another class, its subject can be a member of the class, override its method, and so on, which is the same as any other standard class. If an anonymous class implements an interface, its subject must implement the interface method.
For example:
-
- InterfacePR
-
- {
-
- VoidPrint1 ();
- }
-
- PublicClassNonameclass
-
- {
-
- PublicPR dest()
-
- {
- ReturnNewPR(){
-
- PublicVoidPrint1()
-
- {
- System. Out. println ("Hello world !! ");
-
- }
-
- };
-
- }
-
- PublicStaticVoidMain (string ARGs [])
- {
-
- Nonameclass c =NewNonameclass ();
-
- PR hW = C. DEST ();
-
- HW. print1 ();
-
- }
-
- }
PR can also be a class, but the method you call externally must declare in your class or interface that the external cannot call the internal method of the anonymous class
From: http://blog.sina.com.cn/s/blog_62ea4cf40100mubj.html
Click events in Android
Button BTN = (button) This. findviewbyid (R. Id. button1 );
BTN. setonclicklistener (New button. onclicklistener (){
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
}
});
New is to create a button. onclicklistener object, followed by {}
Indicates that the operation in the brackets acts on the default object, and the above JavaProgramIs followed by a function body.
This usage is used to create an object instance and override
It is a function. It is an onclicklistener
An Implementation of the interface.
Multithreading in Android
Private runnable mrunnable = new runnable ()
{
@ Override
Public void run (){
// Todo auto-generated method stub
Try
{
Thread. Sleep (5000 );
Mhandler. sendmessage (mhandler. obtainmessage ());
}
Catch (interruptedexception E)
{
}
}
};
Public handler mhandler = new handler ()
{
Public void handlemessage (Message MSG)
{
Super. handlemessage (MSG );
Reflesh ();
}
};