Tạo một thư mục trực tiếp của trận động đấtTrong ví dụ sau đây, bạn mở rộng các ứng dụng động đất một lần nữa-thời gian này để bao gồm một thư mục Live sẽ hiển thị cường độ và vị trí của mỗi trận động đất. Thư mục sống kết quả là rất tương tự như các Widget xem bộ sưu tập, bạn tạo ra trước đó trong chương này, làm cho nó một alterna¬tive hữu ích cho các thiết bị chạy Android bản phát hành trước khi Android 3.0.1. bắt đầu bằng cách sửa đổi các lớp học EarthquakeProvider. Tạo ra một định nghĩa URI tĩnh mới sẽ được sử dụng để trở về sống thư mục:khu vực tĩnh cuối cùng Uri LIVE_FOLDER_URI =URI.parse ("content://com.paad.provider.earthquake/live_folder");2. sửa đổi các đối tượng uriMatcher, và getType phương pháp để kiểm tra cho URI yêu cầu mới này:trận động đất riêng int tĩnh cuối cùng = 1; riêng tĩnh cuối cùng int QUAKE_ID = 2; riêng tĩnh cuối cùng int tìm kiếm = 3; riêng tĩnh cuối cùng int LIVE_FOLDER = 4;riêng tĩnh cuối cùng UriMatcher uriMatcher;Phân bổ các đối tượng UriMatcher, nơi một URI kết thúc bằng 'đất' sẽ //correspond để yêu cầu tất cả các trận động đất, và động đất với một //trailing ' / [rowID]' sẽ đại diện cho một hàng duy nhất trận động đất. tĩnh {}uriMatcher = mới UriMatcher(UriMatcher.NO_MATCH);uriMatcher.addURI ("com.paad.earthquakeprovider", "động đất", trận động đất); uriMatcher.addURI ("com.paad.earthquakeprovider", "đất / #", QUAKE_ID); uriMatcher.addURI ("com.paad.provider.Earthquake", "live_folder", LIVE_FOLDER);uriMatcher.addURI ("com.paad.earthquakeprovider",SearchManager.SUGGEST_URI_PATH_QUERY, tìm kiếm); uriMatcher.addURI ("com.paad.earthquakeprovider",SearchManager.SUGGEST_URI_PATH_QUERY + "/ *", tìm); uriMatcher.addURI ("com.paad.earthquakeprovider", SearchManager.SUGGEST_URI_PATH_SHORTCUT, tìm kiếm); uriMatcher.addURI ("com.paad.earthquakeprovider",SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/ *", tìm);}© Ghi đèkhu vực String getType(Uri uri) {switch (uriMatcher.match(uri)) {}trường hợp các trận động đất | LIVE_FOLDER: trở về
đang được dịch, vui lòng đợi..