我想在小部件裏面使用recyclerview(就像GMail小部件一樣)。我使用LinearLayout創建了RecyclerAdapter類,recycleritem佈局和小部件佈局作爲根視圖。所有似乎都很好,但我不知道如何訪問那些只有remoteviews可用的widget的佈局。以下是我卡在的代碼:Android-在小部件裏面使用RecyclerView
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.schedule_today_widget);
ScheduleActivity scheduleActivity = new ScheduleActivity();
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
int week = scheduleActivity.currentWeek(context);
ArrayList<Lesson> mDataSet = scheduleActivity.getDataSet(week, day, context);
mRecyclerView = (RecyclerView) views ...
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
謝謝。
==編輯==
我想從小部件的更新方法訪問recyclerview和recycleradapter。在常規的活動我已經做了這樣的:
mRecyclerView = (RecyclerView) findViewById(R.id.schedule_monday_card);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new ScheduleRecyclerAdapter(myDatasetMonday, context);
mRecyclerView.setAdapter(mAdapter);
但我不能做到這一點這種方法的原因上下文裏面沒有讓我用findViewById()或任何東西。
==編輯==
好吧,現在我應該使用ListView。但我仍然不知道如何通過onUpdate方法訪問我的ListView的小部件佈局?
你的問題在我看來很模糊,一點解釋可能對我們有些幫助;你想要訪問哪些佈局? –