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)
.
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.
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.
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:
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.
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:
Please check the github project and above sample code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With