Android dynamic events

Source: Internet
Author: User

I just learned about Android and saw that the events in the book have always been fixed. I am not quite clear about this in Java. What kind of Anonymous class should I think, the event can be specified at runtime for flexibility.

So I searched from the Internet (my foundation is poor, there is no way ).

Lab successfulCode:

 

Package Android. zziss. Hello;

Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. widget. Button;
Import Android. widget. Toast;

public class helloactivity extends activity {
/** called when the activity is first created. */
private button m_button;
private btnlistener Lis;
@ override
Public void oncreate (bundle savedinstancestate) {
super. oncreate (savedinstancestate);
setcontentview (R. layout. main);
m_button = (button) This. findviewbyid (R. id. btn1);
Lis = new btnlistener ();
m_button.setonclicklistener (LIS);
}< br>
}

Class btnlistener implements view. onclicklistener
{
Public void onclick (view v ){
// Todo auto-generated method stub
Button BTN = (button) V;
BTN. settext ("AAAAA ");
}
}

It's easy, but I didn't know it at the time. It seems that the basics are not good. I still have to learn the basics.

 

For the first Android project, record it

Related Article

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.