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

How to implement listeners in android

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how to achieve listeners in android. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Code sharing:

Import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Button button1= (Button) findViewById (R.id.button1) Button1.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {Intent intent=new Intent (MainActivity.this,Main2Activity.class); startActivity (intent);}})

The bag behind the import will be automatically given to you by lighting a small light bulb after the system reports an error.

Pay attention to the case. Be careful not to repeat your name. The name should be as practical as possible.

In the process of Android application development, common listening events are as follows:

(1) ListView event listening

SetOn ItemSelectedListener: triggered when the mouse is scrolled

SetOnItemClickListener: triggered when clicked

(2) EditText event listening

SetOnKeyListener: triggered when you get focus

(3) RadioGroup event monitoring

SetOnCheckedChangeListener: triggered when clicked

(4) CheckBox event monitoring

SetOnCheckedChangeListener: triggered when clicked

(5) Spinner event monitoring

SetOnltemSelectedListener: triggered when clicked

(6) DatePicker event monitoring

OnDateChangedListener: triggered when the date is changed

(7) DatePickerDialog event monitoring

OnDateSetListener: triggered when the date is set

(8) TimePicker event monitoring

OnTimeChangedListener: triggered when time changes

(9) TimePickerDialog event monitoring

OnTimeSetListener: triggered when the time is set

(10) Button.ImageButton event snooping

SetOnClickListener: triggered when clicked

(11) Menu event monitoring

Triggered when onOptionsltemSelected; clicks

(12) Gallery event monitoring

SetOnItemClickListener: triggered when clicked

(13) GridView event monitoring

SetOnltemClickListener: triggered when clicked

These are all the contents of the article "how to implement a listener in android". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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

Development

Wechat

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

12
Report