Android listener instance code
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 package behind import will automatically give you a small light bulb after the system reports an error.
Pay attention to case. Be careful not to duplicate your name. Try to keep the name as practical as possible
During Android application development, common listening events are as follows:
(1) Listview event listener Seton itemselectedlistener: triggered when the mouse scrolls setonitemclicklistener: triggered when clicking
(2) EditText event listener setonkeylistener: triggered when obtaining focus
(3) Radiogroup event listener setoncheckedchangelister: triggered when clicked
(4) Check@R_ 436_ 2419 @ event listener setonchecked changelister: triggered when clicked
(5) spinner event listener setonltemselectedlistener: triggered when clicked
(6) Datepicker event listening
Ondatechangedlistener: triggered when the date changes
(7) DatePickerDialog event listening ondatesetlistener: triggered when setting a date
(8) TimePicker event listener ontimechangedlistener: triggered when the time changes
(9) timepickerdialog event listening ontimesetlistener: triggered when the time is set
(10) Button.imagebutton event listener setonclicklistener: triggered when clicked
(11) Menu event listening: onoptionsltemselected; Triggered when clicked
(12) Gallery event listener setonitemclicklistener: triggered when clicked
(13) GridView event listener setonltemclicklistener: triggered when clicked
The above is the article about Android listener introduced this time. Thank you for your learning and support.