Reputation: 49
I want to use recyclerview inside the widget (like GMail widget does). I've created RecyclerAdapter class, recycleritem layout and widget layout with LinearLayout as a root view. All seems to be fine but I don't know how to access those layouts from widget where remoteviews are available only. Here is the code where I'm stuck:
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);
}
Thank you.
== Edit ==
I want to access recyclerview and recycleradapter from widget's update method. In regular activity I'd have done it like this:
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);
But I can't do this inside of this method cause context does not let me use findViewById() or anything.
== Edit ==
Okay, now I should use ListView. But I still don't know how to access my ListView in widget's layout from onUpdate method?
Upvotes: 0
Views: 1211
Reputation: 144
According to this App Widgets documentation, RecyclerView is not among supported views when using remote views. I am pretty sure that you should use ListView instead, and that Gmail and other similar widgets does so.
Upvotes: 3