+ id);Tạo một đối tượng từ xa xem mới bằng cách sử dụng thích hợp / / mục bố cụcRemoteViews rv = mới RemoteViews(context.getPackageName(), R.layout.my_media_widget_item_layout);Gán các giá trị được chiết xuất từ con trỏ chuột để xem từ xa. rv.setImageViewUri (R.id.widget_media_thumbnail, uri);Gán điền vào mục cụ thể mục đích thViews nhà máy được thực hiện, theo sau là các cuộc gọi dữ liệu meta, bao gồm cả getCount, trước khi mỗi người trong số các quan điểm được tái tạo.Ngoài ra, các kỹ thuật được sử dụng để cập nhật ứng dụng Widgets — thay đổi tỷ lệ làm tươi tối thiểu, bằng cách sử dụng Intents và thiết lập hệ thống báo động-cũng có thể được sử dụng để Cập Nhật bộ sưu tập xem widget; Tuy nhiên, chúng sẽ gây ra các Widget toàn bộ sẽ được tái tạo, nghĩa là làm mới bộ sưu tập dựa trên quan điểm dựa trên thay đổi đối với các dữ liệu cơ bản là hiệu quả hơn.Việc tạo ra một Widget xem bộ sưu tập trận động đấtTrong ví dụ này bạn thêm một tiện ích thứ hai ứng dụng trận động đất. Điều này sẽ sử dụng một ListView dựa trên bộ sưu tập xem Widget để hiển thị một danh sách các trận động đất tại.1. bắt đầu bằng cách tạo ra một bố trí cho giao diện người dùng tiện ích xem của bộ sưu tập như là một nguồn XML. Lưu tệp quake_collection_widget.xml trong thư mục res/layout. Sử dụng một cách bố trí khung bao gồm các danh sách để hiển thị các trận động đất và xem văn bản để hiển thị khi bộ sưu tập có sản phẩm nào:t sẽ cư / / mẫu đang chờ giải quyết mục đích được chỉ rõ trong các Widget ứng dụng / / nhà cung cấp. Trong này ví dụ mẫu mục đích chỉ định / / hành động ACTION_VIEW.Ý định fillInIntent = mới Intent(); fillInIntent.setData(uri);rv.setOnClickFillInIntent (R.id.widget_media_thumbnail,fillInIntent);trở về rv;}khu vực int getViewTypeCount() {}Số lần xem khác nhau định nghĩa để sử dụng.Đối với các nhà cung cấp nội dung, điều này hầu như luôn luôn sẽ là 1. trở về 1;}khu vực boolean hasStableIds() {}ID nhà cung cấp nội dung phải độc đáo và vĩnh viễn. trả lại sự thật;}khu vực void onDestroy() {}Đóng kết quả con trỏ. c.Close();}công RemoteViews getLoadingView() {}Sử dụng mặc định tải xem. trở về null; Này thay thế linh hoạt hơn để lộ dữ liệu cung cấp nội dung trên màn hình là một replace¬ment cho Live Folders, bây giờ bị phản đối.Làm mới các widget xem bộ sưu tập của bạnWidget quản lý ứng dụng bao gồm các phương pháp notifyAppWidgetViewDataChanged, cho phép bạn chỉ định một Widget ID (hoặc mảng ID) để Cập Nhật, cùng với nhận dạng tài nguyên cho col¬lection xem bên trong mà phụ tùng có nguồn dữ liệu bên dưới đã thay đổi:appWidgetManager.notifyAppWidgetViewDataChanged (appWidgetIds,R.ID.widget_stack_view);Điều này sẽ gây ra bộ xử lý onDataSetChanged trong điều khiển từ xa liên kết
đang được dịch, vui lòng đợi..