Android Interview Collection dialog box, information tips and menus

Source: Internet
Author: User

1. How do I use Alertdialog to display a list?
    • Use the AlertDialog.Builder.setItems method.
    • Defining the Dialoginterface.onclicklistener Listener in Setitems

2. How do I use Alertdialog to implement a radio button?
    • Defines a string array that is used to populate the options
    • New A Alertdialog.builder object
    • Setsinglechoiceitems (array, -1,new onclicklistener{})

3. How do I use Alertdialog to achieve multiple selections?
    • Defines a string array that is used to populate the options
    • New A Alertdialog.builder object
    • Setmultichoiceitems (array, new boolean[]{default},new Dialoginterface.onmultichoiceclicklistener () {...})

4. How do I change the location of the dialog?
    • Use the Window object to get the object of the dialog box at the location of the Windows, Window Window=alertdialog.getwindow ();
    • Then use Window.setgravity (gravity.top| Gravity.left) Setting the location

5. How do I change the transparency of a dialog box?
    • Object that gets the position of the dialog window using the Window object, window Window=alertdialog.getwindow ();
    • Get windowmanager.layoutparams layout parameters using Window.getattributes
    • You can then set the alpha in the layout parameter to a floating-point number
    • Finally, call the Window object window.setattributes to reset the overridden properties.

6. Please write out the Java code that displays a toast message box?
    • Toast Texttoast=toast.maketext (This, "My Information", Toast.length_long);
    • Texttoast.show ();

7. How can I customize the length of the toast display?
    • A reflection mechanism is needed to implement
    • Call Toast.TN.show to display, call Toast.TN.hide to close
    • So you need to get the MTN variable (reflection implementation) from the Toast object first
    • The Show method is then always obtained from the TN object (reflection implementation)

8. Describe the steps to display a Notificationmanager object on the status bar?
    • Get the Notificationmanager object first, Getsystemservice (Notification_service) to get the object
    • Directly create a notification,new Notification (R.drawable.icon, "message ...", System.currenttimemillis ());
    • Create an associated application class, Pendingintent object, Pendingintent.getactivity (This,0,getintent (), 0), guarantee program shutdown, object not freed
    • Set notification details, Notification.setlatesteventinfo (this, "cooler weather, attention to add clothing", Pendingintent object);
    • Display notifications to manage instances with notifications. Notify (R.drawable.icon,notification)

9. What can I do to bring up an activity after clicking notification?
    • Use the Pendingintent.getactivity method to get a Pendingintent object that creates a class for the associated application. The Instant app is closed and the object is still there.
    • Call Mode: Notification.setlatesteventinfo (this, "message title", "Message content", above Pendingintent object).
    • How to send a broadcast: Pendingintent.getbroadcast (this,1,intent,pendingintent.flag_update_current);
    • How to start the service: Pendingintent.getservice (this,1,intent,pendingintent.flag_update_current);

10. How do I clear notification from the status bar?
    • Using the Notificationmanager.cancel method
11. How do I customize notification?
    • Remoteviews class to mate, often used for notifications and desktop widgets
    • Mode of Use: Remoteviews remoteviews=new remoteviews (Getpackagename (), r.layout. Layout name);
    • Notice how to associate: notification.contentview=remoteviews;

12. Describe how you can add an option menu to an activity?
    • Implementing the Activity.oncreateoptionsmenu Method
    • Adding menus is added by menu.add

13. How do I customize the Options menu?
    • The custom Options menu simulates the Options menu with the Popupwindow object.
    • Display and close the custom Options menu by overriding onkeydown.

Android Interview Collection dialog box, information tips and menus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.