Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Click event

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. Click events in several ways:

> > 1, anonymous inner class

Public class MainActivity extends Activity {

Private Button btn

Private TextView tv_show

@ Override

Protected void onCreate (Bundle savedInstanceState) {

Super.onCreate (savedInstanceState)

SetContentView (R.layout.activity_main)

Btn = (Button) findViewById (R.id.btn)

Tv_show = (TextView) findViewById (R.id.tv_show)

/ / the first anonymous inner class

Btn.setOnClickListener (new OnClickListener () {

@ Override

Public void onClick (View v) {

Tv_show.setText ("OK, I'll be right there!")

}

});

}

}

> > 2, the method implemented by the class

Private void clickTwo () {

Btn.setOnClickListener (this)

}

@ Override

Public void onClick (View v) {

Tv_show.setText ("OK, I'll be right there!")

}

> > 3PowerXML layout onClick

/ * *

* the third method: the first modification uses public, and the second method contains View.

* @ param v

, /

Public void clickThree (View v) {

Tv_show.setText ("attention, everyone: Mr. Cang came to Huayu Class 6 to inspect this afternoon!")

}

> > 4, the fourth method

Public void onClick (View v) {

Switch (v.getId ()) {

Case R.id.btn:

Tv_show.setText ("OK")

Break

Case R.id.btn2:] [

Tv_show.setText ("OK, I'll be right there!")

Break

Case R.id.btn3:

Tv_show.setText ("all right, I'll be right there! see you at Huayu Grove tonight!")

Break

Default:

Break

}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report