1. How to implement a hint when testing
can use
- Toast.maketext (This, "It's a hint", toast.length_short). Show ();
- Take a hint from the resource file String.xml
- Toast.maketext (This, getString (r.string.welcome), Toast.length_short). Show ();
This hint will disappear after a few seconds.
2. Alertdialogcan be used. Builder only generates a prompt box.
such as the MessageBox.
- new Alertdialog. Builder (this)
- . Settitle ("Android tips")
- . Setmessage ("This is a hint, make sure")
- . Show ();
With a definite dialog box
- New Alertdialog. Builder (this)
- . Setmessage ("This is a second hint")
- . Setpositivebutton ("OK",
- New Dialoginterface.onclicklistener () {
- public void OnClick (Dialoginterface dialoginterface, inti) {
- //Button event
- }
- })
- . Show ();
Alertdialog. Builder also has a lot of complicated usage, with OK and cancel dialogs
- New Alertdialog. Builder (this)
- . Settitle ("hint")
- . Setmessage ("OK exit?")
- . SetIcon (R.drawable.quit)
- . Setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
- public void OnClick (Dialoginterface dialog, int whichbutton) {
- Setresult (RESULT_OK); //OK button event
- Finish ();
- }
- })
- . Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
- public void OnClick (Dialoginterface dialog, int whichbutton) {
- //Cancel button event
- }
- })
- . Show ();
The use of 3.menu.
- Public static final int item_1_id = Menu.first;
- Public static final int item_2_id = Menu.first + 1;
- Public static final int item_3_id = Menu.first + 2;
- public boolean Oncreateoptionsmenu (Menu menu) {
- Super.oncreateoptionsmenu (menu);
- Menu with no icon
- Menu.add (0, item_1_id, 0, "item-1");
- Menu with icon
- Menu.add (0, item_2_id, 1, "Item-2"). SetIcon (R.DRAWABLE.EDITBILLS2);
- Menu.add (0, item_3_id, 2, "item-3"). SetIcon (R.DRAWABLE.BILLSUM1);
- return true;
- }
- public boolean onoptionsitemselected (MenuItem item) {
- switch (Item.getitemid ()) {
- Case 1:
- Toast.maketext (This, "menu1", Toast.length_short). Show ();
- return true;
- Case 2:
- return true;
- Case 3:
- return true;
- }
- return false;
- }
4.switching of Activity
2 activity switching, no data transfer
- From A to B
- Intent Intent = new Intent ();
- Intent.setclass (A. This, B.class);
- StartActivity (Intent);
Transfer data between 2 activity
Some of the related functions
Startactivityforresult
Public final void Setresult (int resultcode, String data)
callback function
protected void Onactivityresult (int requestcode, int resultcode, Intent data)
For example A to B, get data from B
- A to B
- static final int rg_request = 0;
- Intent Intent = new Intent ();
- Intent.setclass (A. This, B.class);
- Startactivityforresult (intent,rg_request);
- Processing in B
- Bundle bundle = new bundle ();
Bundle.putstring ("DataKey", Edittext.gettext (). toString ());//write data to the bundle
Intent mintent = new Intent ();
Mintent.putextras (bundle);
Setresult (RESULT_OK, mintent);
Finish ();
- Finally, the data is received in the callback function of a.
- if (Requestcode = = rg_request) {
if (ResultCode = = result_canceled)
Settitle ("Canceled ...");
else if (ResultCode = = RESULT_OK) {
Settitle (String) Data.getcharsequenceextra ("DataKey");
}
}
Some of the Android tips box