How To Refresh Widget Listview When Button Refresh Is Clicked?
I'm creating a Widget with ListView on it. Displaying the result from the Web Service in the ListView is okay. I created a class which is my WidgetService that extends to RemoteVie
Solution 1:
In my onUpdate
I set an Action to be called in my onReceive
, and also put the appWidgetIds
to be used as well in the onReceive
Intent refreshIntent = newIntent(context, WidgetProvider.class);
refreshIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
then in onReceive
I call the onUpdate
if (intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE)) {
Bundle extras = intent.getExtras();
if (extras != null) {
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
if (appWidgetIds != null && appWidgetIds.length > 0) {
Toast.makeText(context, "REFRESH", Toast.LENGTH_SHORT).show();
this.onUpdate(context, AppWidgetManager.getInstance(context), appWidgetIds);
}
}
}
Solution 2:
arrayList = new ArrayList<AllPostsProvider>();
arrayList.add(all_contents);
AllPostReCyclerViewAdapter = new AllPostReCyclerViewAdapter(arrayList,getApplicationContext());
and when click refreash button
arrayList.clear();
arrayList = new ArrayList<AllPostsProvider>();
arrayList.add(all_contents);
AllPostReCyclerViewAdapter = new AllPostReCyclerViewAdapter(arrayList,getApplicationContext());
Post a Comment for "How To Refresh Widget Listview When Button Refresh Is Clicked?"