Tại thời điểm này, GUI sẽ được hoàn thành, do đó, bắt đầu từ các ứng dụng nên hiển thị cho bạn màn hình trong hình 17-2.1. tạo ra một mới loạt các danh sách của dây trong hoạt động EmergencyResponder để lưu trữ số điện thoại đến yêu cầu cho tình trạng của bạn. Ràng buộc trong danh sách mảng để xem danh sách bằng cách sử dụng một Adapter Array trong các hoạt động onCreate phương pháp, và tạo ra một đối tượng ReentrantLock mới để bảo đảm thread-safe xử lý danh sách mảng. Có này opportu¬nity để có được một tham chiếu đến các hộp kiểm và để thêm nhấp vào nghe cho mỗi nút phản ứng. Mỗi nút nên gọi phương pháp trả lời, trong khi các nút thiết lập Auto Responder nên gọi khai startAutoResponder.ReentrantLock khóa;Hộp kiểm locationCheckBox;ArrayList requesters;ArrayAdapter AA;© Ghi đèkhu vực void onCreate(Bundle savedlnstanceState) {super.onCreate(savedlnstanceState); setContentView(R.layout.main);khóa = mới ReentrantLock(); requesters = mới ArrayList(); wireUpControls();}riêng khoảng trống wireUpControls() {}locationCheckBox = (CheckBox)findViewByld(R.id.checkboxSendLocation);ListView myListView = (ListView)findViewByid(R.id.myListView);int layoutID = android. R.layout.simple_list_item_1;AA = mới ArrayAdapter(này, layoutID, requesters);myListView.setAdapter(aa);Button okButton = (Button)findViewById(R.id.okButton); okButton.set0nClickListener (new View.0nClickListener() {{} khu vực void onClick (View xem)trả lời (đúng, locationCheckBox.isChecked());}});Button notOkButton = (Button)findViewByid(R.id.notOkButton); not0kButton.set0nClickListener (new View.0nClickListener() {{} khu vực void onClick (View xem)trả lời (false, locationCheckBox.isChecked());}});Nút autoResponderButton =(Button)findViewByid(R.id.autoResponder); autoResponderButton.set0nClickListener (new View.0nClickListener() {khu vực void onClick(View view) {startAutoResponder();}});}công cộng hiệu ứng (boolean ok, boolean includeLocation) {) riêng void startAutoResponder() {)2. tạo ra một máy thu phát sóng sẽ lắng nghe cho các tin nhắn SMS tin nhắn. Bắt đầu bằng cách tạo ra một biến chuỗi tĩnh mới để lưu trữ các đến tin nhắn SMS thông báo ý định hành động, và sau đó tạo ra một máy thu phát sóng mới như là một biến trong hoạt động EmergencyResponder. Người nhận phải lắng nghe cho các tin nhắn SMS tin nhắn và gọi phương pháp requestReceived khi nó thấy tin nhắn SMS có chứa các © string/querystring tài nguyên bạn đã xác định trong bước 4.khu vực tĩnh cuối cùng String SMS_RECEIVED =
đang được dịch, vui lòng đợi..