How to create a Listview using remoteview?

I am trying to make a dynamic listview in widgets using remoteview , since I need this listview icon of application icons in widgets. I want to show incoming notifications from all applications that are separated from the application. I want to create a permanent list of notifications, and when a user clicks on the application icon from the list, this particular notification will be displayed. I use API 19 to receive all notifications and also successfully, but I do not know how I can create a listview in widgets with remoteview , as well as with drawables(Icons) .

+5
source share
2 answers

Are you browsing or trying to use other examples that have a ListView in widgets? Please check out the Weather Widget demo available on github.

the code:

  public class MyWidgetProvider extends AppWidgetProvider { private static HandlerThread sWorkerThread; private static Handler sWorkerQueue; public MyWidgetProvider() { // Start the worker thread sWorkerThread = new HandlerThread("MyWidgetProvider-worker"); sWorkerThread.start(); sWorkerQueue = new Handler(sWorkerThread.getLooper()); } public void onUpdate(Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int i = 0; i < appWidgetIds.length; ++i) { ... final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); views.setRemoteAdapter(R.id.lvWidget, svcIntent); sWorkerQueue.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub views.setScrollPosition(R.id.list, 3); appWidgetManager.partiallyUpdateAppWidget(appWidgetIds[i], views); } }, 1000); appWidgetManager.updateAppWidget(appWidgetIds[i], views); ... } } } 

Which would look like this:

enter image description here

Please check out the github project and sample code.

+4
source

I already tried from @iDroid Explorer solution from one of my previous answers. But listview did not appear in the edge panel (PS: I wanted this to be implemented in the galaxy panel).

So, I tried under the code:

  private RemoteViews updateWidgetListView(Context arg0, int i) { //which layout to show on widget RemoteViews remoteViews = new RemoteViews(arg0.getPackageName(), R.layout.activity_main_sub); //RemoteViews Service needed to provide adapter for ListView Log.d("fff", "updateWidget: "+ i); Intent svcIntent = new Intent(arg0, MyService.class); //passing app widget id to that RemoteViews Service svcIntent.putExtra("Id", i); Log.d("fff", "receiver:"+appnM); svcIntent.putExtra("appname", appnM); //setting a unique Uri to the intent //don't know its purpose to me right now svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); //setting adapter to listview of the widget remoteViews.setRemoteAdapter(i, R.id.list_icon,svcIntent); // remoteViews.setRemoteAdapter(i, svcIntent); arg0.startService(svcIntent); //setting an empty view in case of no data remoteViews.setEmptyView(R.id.list_icon, R.id.empty_view); Log.d("fff","end of myReceiver"); return remoteViews; } 

And in the myService class, I filled in the necessary elements in the list.

I need help from an example: WidgetListView1, which I found from random searches.

+1
source

Source: https://habr.com/ru/post/1212415/


All Articles