- Add Common Unit file com: Java
Package Com.example.myapplication;import Android.app.alertdialog;import Android.content.context;import Android.widget.toast;public class COM {//hint information public static void ShowMsg (String msg,context Context) { Alertdialog.builder dlg = new Alertdialog.builder (context); Dlg.settitle ("hint"); Dlg.setmessage (msg); Dlg.setpositivebutton ("OK", null); Dlg.show ();} Flashing hint public static void Displaytoast (String msg,context context) {Toast.maketext (context, MSG, toast.length_short). Show ();}}
2. Drag in a Button, Button Event association method name
3.mainactivity.java New method name btn_clicked and call the Com.java method
public void btn_clicked (view view) { com. ShowMsg ("This is the Cue box", mainactivity.this); Com. Displaytoast ("This is a flashing hint", getbasecontext ()); }
4. Operation Effect
Android---hellword Simple tips box