Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Listview with help of remoteview?

I am trying to make dynamic listview in widget with help of remoteview, as I wanted this listview of application icons in a widget. I want to show incoming notifications from all apps which are separated application wise. I want to create standing notification list and when user clicks on application icon from listview, that particular notification will be displayed. I am using API 19 for getting all notification and also succeeded but I don't know how I can create Listview in widget with Remoteview and also with drawables(Icons).

like image 850
kiturk3 Avatar asked Feb 02 '15 07:02

kiturk3


People also ask

How to make a listview in Android?

Most uses of listview is a collection of items in vertical format, we can scroll up/down and click on any item. This example demonstrate about How to make a ListView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

What is the use of listview builder?

ListView.builder () constructor is appropriate for list views with ahe large (or infinite) number of children because the builder is called only for those children that are visible. Providing the non-null itemCount improves the ability of the ListView to estimate the maximum scroll extent.

How many types of ListViews are there?

There are four types of ListViews. ListView is the default constructor of a ListView class. A ListView takes the list of children and makes it scrollable. The builder () constructor constructs the repeating list of items. The constructor takes two main parameters:

What happens if we don’t use listview?

If we do not use ListView, it will throw a warning in a yellow line to indicate that we need to use some widget to show the proper user content, and that is why we will use the ListView widget Flutter. Flutter provides ListView.builder which can be used to generate dynamic content from external sources. There are four types of ListViews.


Video Answer


1 Answers

Have you search or try with other examples having ListView in widget? Please check the Weather Widget demo available on github.

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 will behave like below:

enter image description here

Please check the github project and above sample code.

like image 199
Shreyash Mahajan Avatar answered Oct 09 '22 22:10

Shreyash Mahajan