TAILIEUCHUNG - professional android application development phần 4

Bạn sẽ bổ sung thêm khả năng để loại bỏ các mục từ menu ngữ cảnh và hoạt động, và cải thiện việc sử dụng các không gian màn hình bằng cách hiển thị hộp nhập văn bản khi thêm một mục lý sự kiện này được kích hoạt bất cứ khi nào một mục | Chapter 4 Creating User Interfaces This event handler is triggered whenever a Context Menu Item is selected within the Activity. A skeleton implementation is shown below Override public boolean onContextitemSelected Menuitem item item . Handle menu item selection . return false To-Do List Example Continued In the following example you ll be adding some simple menu functions to the To-Do List application you started in Chapter 2 and continued to improve previously in this chapter. You will add the ability to remove items from Context and Activity Menus and improve the use of screen space by displaying the text entry box only when adding a new item. 1. Start by importing the packages you need to support menu functionality into the ToDoList Activity class. import import import import 2. Then add private static final variables that define the unique IDs for each Menu Item. static final private int ADD_NEW_TODO static final private int REMOVE_TODO 1 3. Now override the onCreateOptionsMenu method to add two new Menu Items one to add and the other to remove the to-do item. Specify the appropriate text and assign icon resources and shortcut keys for each item. Override public boolean onCreateOptionsMenu Menu menu menu Create and add new menu items. Menuitem itemAdd 0 ADD_NEW_TODO Menuitem itemRem 0 REMOVE_TODO Assign icons Allocate shortcuts to each of them. 107 Chapter 4 Creating User Interfaces 0 a 1 r return true If you run the Activity pressing the Menu button should appear as shown in Figure 4-7. Figure 4-7 4. Having populated the Activity Menu create a Context Menu. First modify onCreate to register the ListView to

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.